【问题标题】:using core-js with TypeScript使用带有 TypeScript 的 core-js
【发布时间】:2016-12-18 18:22:14
【问题描述】:

http://kangax.github.io/compat-table/es6/ 的 ES6 Kangax 兼容性表显示了“TypeScript + core-js”的结果。我需要 core-js 才能使用像 String#startsWith 这样的 ES6 方法。我无法弄清楚如何告诉 TypeScript 编译器考虑 core-js 并且找不到示例。如何在 TypeScript 中使用 core-js?

【问题讨论】:

标签: javascript ecmascript-6 typescript1.5


【解决方案1】:

如果你使用 Typescript 2.0,你可以使用@types 来解决这个问题。

@types 和类型

当您编译 typescript 代码时,默认情况下所有可见的 @types 包都包含在您的编译中。任何封闭文件夹的node_modules/@types 中的包都被视为可见;具体来说,这意味着包在:

  • ./node_modules/@types/,
  • ../node_modules/@types/,
  • ../../node_modules/@types/,

等等。

@types/core-js 提供 core.js 的定义,您可以将其安装为其他模块。

npm install --save-dev @types/core-js

更多信息请访问:tscconfig.json

祝你好运。

【讨论】:

    【解决方案2】:

    Typescript 存储库提供 standard definitions for ES6 功能。

    我想如果你想使用一些超出 ES6 的 core-js 的功能,你必须自己添加定义文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 2017-06-19
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 2019-11-29
      相关资源
      最近更新 更多