【问题标题】:typescript tsc is not excluding @types/corejstypescript tsc 不排除 @types/corejs
【发布时间】:2017-03-23 12:10:08
【问题描述】:

Tsconfig:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true,
"lib": [
  "es6",
  "dom"
],
"types": [
  "hammerjs",
  "jasmine",
  "node",
  "selenium-webdriver",
  "webpack",
  "core-js",
  "google-maps"
]
},
"exclude": [
"node_modules"
"e2e"
],
"include": [
"src/**/*"
],
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"!./node_modules/**/*.ts",
"./src/custom-typings.d.ts"
],

}

执行 tsc 时出现以下错误:

node_modules/@types/core-js/index.d.ts(262,5):错误 TS2687:“标志”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(276,5):错误 TS2687:“EPSILON”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(311,5):错误 TS2687:“MAX_SAFE_INTEGER”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(318,5):错误 TS2687:“MIN_SAFE_INTEGER”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(457,5):错误 TS2403:后续变量声明必须具有相同的类型。变量 '[Symbol.toStringTag]' 必须是 '"Symbol"' 类型,但这里有 'string' 类型。 node_modules/@types/core-js/index.d.ts(457,5):错误 TS2687:'[Symbol.toStringTag]' 的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(464,5):错误 TS2687:“原型”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(492,5):错误 TS2687:“hasInstance”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(498,5):错误 TS2687:“isConcatSpreadable”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(504,5):错误 TS2687:“迭代器”的所有声明必须具有相同的修饰符。 node_modules/@types/core-js/index.d.ts(510,5): 错误 TS2687:

的所有声明

为什么执行 tsc 命令时不会忽略 node_modules。 我在 2.0.3 版本中使用打字稿

【问题讨论】:

    标签: javascript typescript tsc


    【解决方案1】:

    您的tsconfig.json 文件在"types" 属性中列出core-js。这指示编译器包含node_module\@types\core-js。如果您不需要它,请删除该条目。

    有关@types 的更多详细信息,请参阅http://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types,以及tsconfig.json 中的types

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 2018-08-19
      • 2022-10-14
      • 2018-11-04
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      相关资源
      最近更新 更多