gpt4 book ai didi

typescript - typescript 中的lib来自哪里?

转载 作者:行者123 更新时间:2023-12-02 15:14:15 25 4
gpt4 key购买 nike

我有一个 typescript@2 项目。我想使用一些 ecma2017 功能。我发现可以在 tsconfig.jsoncompilerOptions 中应用 lib:

"target": "es6",
"lib": [
"es2017",
"dom"
],

然而,为什么这是有效的?这些库来自哪里,可以包含哪些库?

我能找到的最接近文档的是这个 this what's new entry :

Downlevel Async Functions

This feature was supported before TypeScript 2.1, but only when targeting ES6/ES2015. TypeScript 2.1 brings the capability to ES3 and ES5 run-times, meaning you'll be free to take advantage of it no matter what environment you're using.

Note: first, we need to make sure our run-time has an ECMAScript-compliant Promise available globally. That might involve grabbing a polyfill for Promise, or relying on one that you might have in the run-time that you're targeting. We also need to make sure that TypeScript knows Promise exists by setting your lib flag to something like "dom", "es2015" or "dom", "es2015.promise", "es5"

但我没有发现它特别有用。

最佳答案

Lib documentation 中引用了编译器选项 lib 的所有值:

List of library files to be included in the 

Possible values are:
► ES5
► ES6
► ES2015
► ES7
► ES2016
► ES2017
► ESNext
► DOM
► DOM.Iterable
► WebWorker
► ScriptHost
► ES2015.Core
► ES2015.Collection
► ES2015.Generator
► ES2015.Iterable
► ES2015.Promise
► ES2015.Proxy
► ES2015.Reflect
► ES2015.Symbol
► ES2015.Symbol.WellKnown
► ES2016.Array.Include
► ES2017.object
► ES2017.SharedMemory
► esnext.asynciterable

Note: If --lib is not specified a default library is injected. The default library injected is:
► For --target ES5: DOM,ES5,ScriptHost
► For --target ES6: DOM,ES6,DOM.Iterable,ScriptHost

关于typescript - typescript 中的lib来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41461797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com