添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Specify library file to be included in the compilation. Requires TypeScript version 2.0 or later.

What does that mean?

This is a new typescript 2 feature and so it still lacks documentation, but you can read about it in the What's new in Typescript 2.0 :

with --lib you can specify a list of built-in API declaration groups that you can chose to include in your project. For instance, if you expect your runtime to have support for Map, Set and Promise (e.g. most evergreen browsers today), just include --lib es2015.collection,es2015.promise. Similarly 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.

There's also a list of the API groups that are supported and a very short example in that link.

I meant that when I specify "lib": ["es5"], does it simply mean that I can use es5 types in ts complaining of compiler, or some kind of poly-fills will be provided by tsc ? courses.indepth.dev Jan 20, 2017 at 15:21 The different libs can be found here: github.com/Microsoft/TypeScript/tree/master/lib They are definition files which the compiler uses Nitzan Tomer Jan 20, 2017 at 15:27 I see, thanks, so this basically means, that if I specify "lib": ["es5"] and don't specify "dom", tsc will complain about usage of DOM specific methods, correct? courses.indepth.dev Jan 20, 2017 at 15:41 Beware that including "es2015.promise" or whatsoever doesn't include a polyfill into your compiled code. Instead you just notify the compiler that your code is using promises and it should be okay with that. If you need to add promises polyfills, consider either importing the polyfill in your code or using babel with corresponding machinery (babel-preset-env) as a post-step (or next loader in webpack) Dmitrii Sorin Jul 26, 2018 at 21:58 These groups make a promise to the compiler, "please don't complain about these APIs, I promise the browser will support them." E.g. If you add es6 and don't include polyfills , old browsers will choke. Steve Clay Aug 3, 2018 at 13:18

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .