typescript tsconfig 选项“lib”有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39303385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:18:50  来源:igfitidea点击:

What does the tsconfig option "lib" do?

typescript

提问by Greg Gum

I have an existing project that has this line in tsconfig.json:

我有一个现有项目,在 tsconfig.json 中有这一行:

lib:["2016", "DOM"]

What is the purpose of this?

这样做的目的是什么?

The only info I could find is this:

我能找到的唯一信息是:

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

指定要包含在编译中的库文件。需要 TypeScript 2.0 或更高版本。

What does that mean?

这意味着什么?

采纳答案by Nitzan Tomer

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:

这是一个新的 typescript 2 特性,因此它仍然缺乏文档,但您可以在 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.

使用 --lib,您可以指定可以选择包含在项目中的内置 API 声明组列表。例如,如果您希望您的运行时支持 Map、Set 和 Promise(例如当今大多数常绿浏览器),只需包含 --lib es2015.collection,es2015.promise。同样,如果您正在使用 --lib es5,es6 处理节点项目,您可以排除不想包含在项目中的声明,例如 DOM。

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

API groups在该链接中还有一个受支持的列表和一个非常简短的示例。