I would like less correct types for the Document
interface. Basically everything is of type Element
when its always HTMLElement
that I want. Littering lines like (document.activeElement.previousElementSibling as HTMLElement).click();
with as
assertions/casts is not making my code any cleaner and creates a lot of friction transitioning from js to ts. Would be great if everything in the Document interface dealt with HTMLElement
or something like Element & Partial<HTMLElement>
.
I tried seeing if Declaration Merging would let some variation like interface Document { getElementsByClassName (classNames: string): HTMLCollectionOf<HTMLElement>;}
to work but it didn't seem like this is the right track.
It looks like typescript 4.5 lets you specify specific lib-dom versions. Is it reasonable or possible to create a user modified lib-dom and target that? (Announcement) (Docs)
Currently using but have no requirements on tsc 4.6.4 and
"compilerOptions": {
"target": "ES2021",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"jsx": "react-jsx",}