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

半世苍凉 提交于 2019-12-12 04:47:16

问题


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


回答1:


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.




回答2:


typescript lib setting dom be included when developing an angular 4

Yes.

Reason

Angular is designed for the DOM.



来源:https://stackoverflow.com/questions/43786728/should-the-typescript-lib-setting-dom-be-included-when-developing-an-angular-4-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!