首页 文章

lib在哪里来自typecsript?

提问于
浏览
1

我有一个打字稿@2项目 . 我想使用一些ecma2017功能 . 我发现可以在 tsconfig.json 中的 compilerOptions 中应用 lib

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

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

最接近我能找到的文件是this what's new entry

下层异步功能在TypeScript 2.1之前支持此功能,但仅在定位ES6 / ES2015时 . TypeScript 2.1为ES3和ES5运行时提供了功能,这意味着无论您使用何种环境,您都可以自由地利用它 . 注意:首先,我们需要确保我们的运行时具有全局可用的符合ECMAScript的Promise . 这可能涉及为Promise抓取polyfill,或者依赖于您在目标运行时可能拥有的polyfill . 我们还需要通过将lib标志设置为“dom”,“es2015”或“dom”,“es2015.promise”,“es5”来确保TypeScript知道Promise存在 .

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

1 回答

  • 2

    compiler option 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
    

相关问题