【问题标题】:Property 'includes' does not exist on type 'string[]' Even I use ES7'string[]' 类型上不存在属性 'includes' 即使我使用 ES7
【发布时间】:2018-12-21 21:39:35
【问题描述】:

我在其他页面发现了这个问题,有人说我应该在tsconfig.josn中更改lib,但是我将compile改为es7后,仍然弹出相同的错误,无法打包和构建。

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

【问题讨论】:

  • 试试es7github.com/Microsoft/TypeScript/issues/11890 会认为他们会是一样的,但你永远不知道。此外,有人说将目标设置为 es2016,但这似乎是一个糟糕的主意,除非您只想支持最新版本的 edge、chrome 和 firefox。

标签: javascript angular typescript package ecmascript-2016


【解决方案1】:

它不能工作的原因是因为我们使用ng-packagr打包部分代码,它没有拿起tsconfig.json lib。

我的问题的解决方案是,将语言级别添加到 ng-package.json 中,它应该覆盖 traget:“es5”,并且能够构建 es7 文件。

{
  "ngPackage": {
    "lib": {
      "languageLevel": ["dom", "es2017"]
    }
  }
}

【讨论】:

    【解决方案2】:

    做同样的改变,即

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

    tsconfig.lib.json 中。您的图书馆项目。

    默认是2015

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-02
      • 2018-05-28
      • 2018-10-31
      • 2021-05-31
      • 2017-08-21
      • 2018-12-28
      • 2021-09-26
      • 2023-01-19
      相关资源
      最近更新 更多