angulartypescripttypescript2.2

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


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


Solution

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