Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is dom for in the lib array in the tsconfig.json file in Angular?

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?

like image 775
Кatya Avatar asked Aug 16 '18 18:08

Кatya


People also ask

What is Lib in Tsconfig json?

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 ).

What should I put in Tsconfig json?

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.

What does include in Tsconfig do?

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.


1 Answers

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

like image 127
hgiasac Avatar answered Oct 05 '22 06:10

hgiasac