JSでの型キャストを行う方法
方法
JSで型キャストを行う場合は/** @type {型} */と記述する。
const numStr = "7";
const num = 1 + /** @type {Int} */numStr;JSは動的型付けなのであまりこういう場面は少ないが、例外がある。
let table = document.querySelector('.field-table');
let tbody = document.querySelector('#field-tbody');
table?.removeChild(/** @type {Element} */ (tbody));それは要素を取得する際に、要素がない可能性があるので
tbodyの型としてはElement | nullとなる。