Should the typescript lib setting dom be included when developing an angular 4 component?

202 views Asked by At

In this article on distributing an angular library the author says that it's a good idea to not touch the dom directly because it makes the component unusable inside web workers.

Should we thus leave dom out of the typescript lib compiler option or are there certain use cases where we absolutely need it? Here's an example with dom included:

"compilerOptions": {
  "target": "es5",
  "module": "es2015",
  "lib": ["es2015", "dom"]
},

The sample tsconfig.json compiler options includes dom ...

2

There are 2 answers

0
Meirion Hughes On BEST ANSWER

It doesn't compile without "dom". The reason is that the angular libraries export methods/classes that consume/return "dom" types. So when you go to compile against angular, your compilation fails because it cannot find the types.

0
basarat On

typescript lib setting dom be included when developing an angular 4

Yes.

Reason

Angular is designed for the DOM.