TypeScript TSConfig CompilerOptions ES2017 目标和库

标签 typescript ecmascript-6 babeljs tsconfig ecmascript-2017

我正在开发一个 TypeScript 项目,我们使用 ES2017 作为输出目标,以及其中一个库,因为它将通过 Babel,我们希望支持最新的功能集我们在 Babel 中定位“Env”。

一切似乎都很好,所以我不太担心。但是,我不知道幕后发生了什么或者“lib”选项真正做了什么(除了告诉我的 IDE 我可以做什么,比如传播操作、Promises 等),以及它是否更多/指定 TypeScript 的最高输出然后编译到 Babel 中非常具体的目标的效率较低。这也是通过 WebPack 进行的,因此我们利用了 tree shaking。

第二个问题是,当“ES2017”包含在库中时,它是否包含 ES2015 和 ES2016 中的所有功能(换句话说,是否有任何理由包含 ES2015 和/或 ES2016,而 ES2017 在列表中?)

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "ES2015",
    "moduleResolution": "Node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "allowSyntheticDefaultImports": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "pretty": true,
    "alwaysStrict": true,
    "lib": [
      "DOM",
      "ES2017",
      "DOM.Iterable",
      "ScriptHost"
    ],
    "baseUrl": "./client",
    "paths": {
      "styles/*": ["./app/styles/*"],
      "core/*": ["./app/core/*"],
      "components/*": ["./app/components/*"],
      "containers/*": ["./app/containers/*"],
      "assets/*": ["./assets/*"],
      "config/*": ["./config/*"]
    }
  },
  "files": [
    "./client/custom-typings.d.ts",
    "./client/app/app.ts"
  ]
}

顺便说一句,当在 Babel“Env”中定位“last 1 Chrome version”时,它几乎不做任何转译,这非常令人兴奋。我们只是构建原型(prototype),而不是生产代码,因此我们会在需要支持时专门添加我们需要支持的浏览器,但几乎不会做任何不是 Chrome 的最后 1 或 2 个版本的事情。

最佳答案

看看 libTypescript GitHub 上的可能性的实际实现,似乎 ES2017 包含所有这些包:

/// <reference path="lib.es2016.d.ts" />
/// <reference path="lib.es2017.object.d.ts" />
/// <reference path="lib.es2017.sharedmemory.d.ts" />
/// <reference path="lib.es2017.string.d.ts" />

并且 es2016.d.ts 包含以下引用:

/// <reference path="lib.es2015.d.ts" />
/// <reference path="lib.es2016.array.include.d.ts" />

最后是 es2015.d.ts 引用:

/// <reference path="lib.es2015.core.d.ts" />
/// <reference path="lib.es2015.collection.d.ts" />
/// <reference path="lib.es2015.generator.d.ts" />
/// <reference path="lib.es2015.iterable.d.ts" />
/// <reference path="lib.es2015.promise.d.ts" />
/// <reference path="lib.es2015.proxy.d.ts" />
/// <reference path="lib.es2015.reflect.d.ts" />
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.symbol.wellknown.d.ts" />
/// <reference path="lib.es5.d.ts" />

因此可以安全地假设 es2017 包含大多数 ES 功能。

虽然有趣的是 es6 没有包含在任何地方并且提供它是单独的 file没有任何引用。我真的不知道它是如何工作的,但我认为它是上述某些内容的单独组合。

编辑:

我对上面提到的 es6 困境做了更多研究,并将我的发现发布在不同的 question 中。 .

关于TypeScript TSConfig CompilerOptions ES2017 目标和库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42956326/

相关文章:

javascript - Nodejs5 和 babel 中的 "unexpected token import"?

babeljs - 在 .babelrc 文件中指定 cacheDirectory

node.js - vscode : Can't break on any breakpoint with Visual Studio code when launching with nodemon

angularjs - Chrome 开发工具未映射 ts 源

javascript - Angular 2,Typescript 模块没有导出常量 'FORM_DIRECTIVES'

javascript - 在React中,方法返回无法读取未定义的属性 'target'

javascript - 什么是解构赋值及其用途?

javascript - 我还需要 babel 和 NodeJs5 吗?

unit-testing - TestBed configureTestingModule 在一个模块中定义所有 spec.ts 通用的导入、声明、提供程序和管道 - 模式

reactjs - 我什么时候应该将命名导入与 React hooks 一起使用?