Vector uses tsc to check code for type safety. Whenever we have an Element, we almost certainly have an HTMLElement. As various properties only exist on HTMLElement (see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement) - we need to make sure elements are typed as HTMLElement and not just Element, however many methods return the Element interface instead - most notably querySelector/querySelectorAll.
I think there are two options:
- Add an inline typehint every time we use an Element-returning method:
const foo = /** @type {HTMLElement} */ container.querySelector( '.foo' ), bar = /** @type {HTMLElement} */ container.querySelector( '.bar' ),
- Create utility functions:
/** * @param {string} selector * @param {HTMLElement} [parent=document] * @returns {HTMLElement|null} */ function querySelector( selector, parent = document ) { return parent.querySelector( selector ); }