【问题标题】:Difference in the 'lib' property in tsconfig.json between es6 and es2017?es6 和 es2017 之间 tsconfig.json 中“lib”属性的区别?
【发布时间】:2017-10-08 00:24:57
【问题描述】:

我一直在研究 tsconfig.json 文件中的 compilerOptionslib 属性的可能值的含义。我在 Typescript GitHub 页面上找到了与这些值相对应的相关 d.ts 文件,显然通过使用 ES2017 包含以下 ES 功能:

/// <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" />
/// <reference path="lib.es2015.d.ts" />
/// <reference path="lib.es2016.array.include.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" />

但显然 ES6 不包括在内,并且有自己的 file 不引用任何内容。我的问题是,如果有人知道,是否可以安全地假设通过使用 es2017 我涵盖了所有 es6 功能(从打字的角度来看),还是应该单独包含在 lib 选项中?

例如,像这样:

{
  ...
  "compilerOptions": {
    ...
    "lib": ["es2017", "dom"]
  },
  ...
  }
}

或者这个:

{
  ...
  "compilerOptions": {
    ...
    "lib": ["es2017", "es6", "dom"]
  },
  ...
  }
}

【问题讨论】:

  • ES6 == ES2015
  • @Bergi 并不完全符合 Typescript 的类型。它包括所有 ES2015 的东西和其他东西。请参阅下面的答案。

标签: typescript ecmascript-6 typescript-typings typescript2.0 ecmascript-2017


【解决方案1】:

通过Typescript GitHub 上的lib 文件夹进行一些挖掘和比较后,我发现,在compilerOptionslib 属性中使用es6 对应于这些参考中的代码:

/// <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" />
/// <reference path="lib.dom.d.ts" />
/// <reference path="lib.scripthost.d.ts.d.ts" />
/// <reference path="lib.dom.iterable.d.ts" />

所以回答我的问题,用es2017 正确覆盖es6 的所有内容,tsconfig.json 的该部分应如下所示:

{
  ...
  "compilerOptions": {
    ...
    "lib": ["es2017", "dom", "dom.iterable", "scripthost"]
  },
  ...
  }
}

【讨论】:

    猜你喜欢
    • 2018-05-01
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 2011-06-22
    • 2012-08-27
    • 2011-02-02
    • 1970-01-01
    相关资源
    最近更新 更多