Is it possible to type a DOM element in TypeScript? If it is how do we do? For example, can we do:
var myDocument: any = document;
Is it possible to type a DOM element in TypeScript? If it is how do we do? For example, can we do:
var myDocument: any = document;
tl;dr; Just use document
in your code.
The types of all DOM nodes are already defined in the TypeScript compiler. See the documentation on the compiler option --lib
about the value DOM
.
Notice: You shouldn't do let myDocument: any = document
. The : any
would lose the typing. You can do: let myDocument = document
and the type of myDocument
will be inferred from the type of document
.