In my Angular 6 project, in tsconfig.json and ts.config.spec.json I have this part:
"lib": [
"es2016",
"dom"
]
What is dom
for?
Official documentation here says: "... you can exclude declarations you do not want to include in your project, e.g. DOM if you are working on a node project using --lib es5,es6."
But I am not sure what this means in practice. We do not specify "any declarations you do not want."
My tests were totally broken until I added dom
to the lib
array in tsconfig.spec.ts. What does this do?
TypeScript includes a default set of type definitions for built-in JS APIs (like Math ), as well as type definitions for things found in browser environments (like document ).
The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.
tsconfig include The include property specifies the files to be included in the TypeScript project. You can either include files or file paths like ./src/** to specify what should be included.
dom
lib is a set of JavaScript Web API interfaces, including DOM, DOM Events, Audio, Canvas, Video, XHR API... You can see full source code here
Of course you should include this library if you are developing frontend web. For backend Node.js development, it is optional. However, there is some Node.js package that is used for both frontend and backend. And you will meet type missing error when compiling without including it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With