一个简单的重现仓库: https : npm i && npm run build
,错误是:
node_modules/@types/core-js/index.d.ts(21,14): error TS2300: Duplicate identifier 'PropertyKey'.
node_modules/typescript/lib/lib.es6.d.ts(4133,14): error TS2300: Duplicate identifier 'PropertyKey'.
预期:没有错误,因为app.ts
是空的。 @types/core-js
用于static/app.ts
。
"devDependencies": {
"@types/core-js": "^0.9.34",
"core-js": "^2.4.1",
"typescript": "^2.0.3"
}
需要 lib.es6 中未包含的 core-js 的哪些部分? 你不能简单地不安装@types/core-js
吗?
@aciccarello core-js 和 @types/core-js 由前端在static/app.ts
,这部分运行良好
有 2 个tsconfig.json
,一个用于后端(es6,这里发生错误),另一个用于前端(es5,没有错误,效果很好),
@plantain-00 你发现了吗?
我有一个类似的问题,我想使用 core-js(字典)的一些非标准功能,但类型与 typescripts 库冲突。
@jefbarn对于非标准功能,我没有解决方案。
对于标准功能,我卸载了@types/core-js
,并删除了import "core-js";
,因为 core-js 是 ES2015+ 的 polyfills,所以我可以使用typescript/lib/lib.es6.d.ts
代替, tsconfig.json
好像:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es2015",
"es5",
"dom",
"scripthost"
]
}
}
看来这个问题还是需要的,我重新打开这个。
我在使用@types\core-js
并针对 ES6 时遇到了这个问题
@anorborg我确实使用这样的方法解决了我的情况:
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"lib": ["es5", "dom"],
...
}
@jefbarn确实有效。 基本上core-js
和 typescript 2.x es6.d.ts
库是冲突的,这告诉打字稿不要使用它的es6.d.ts
。 我_认为_更_纯_的解决方案是为core-js
(即core-js-es6-object
)创建一些模块类型定义,而不是包括整个core-js
定义。 我试图在本地启动它,但无法让本地自定义类型工作。 如果我有时间,我会尝试弄清楚并为所有模块创建 PR。
引起注意。
我刚刚使用这个 ts 配置用tsc
2.2.0
创建了一个新项目:
{
"compilerOptions": {
"outDir": "./build/",
"rootDir": "./src/",
"baseUrl": ".",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es6"
},
"include": [
"./src/**/*.ts"
],
"compileOnSave": false
}
这会产生这些错误:
node_modules/@types/core-js/index.d.ts(21,14): error TS2300: Duplicate identifier 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(85,5): error TS2687: All declarations of 'name' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(145,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.
node_modules/@types/core-js/index.d.ts(262,5): error TS2687: All declarations of 'flags' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(276,5): error TS2687: All declarations of 'EPSILON' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(311,5): error TS2687: All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(318,5): error TS2687: All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(457,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'.
node_modules/@types/core-js/index.d.ts(457,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(464,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(492,5): error TS2687: All declarations of 'hasInstance' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(498,5): error TS2687: All declarations of 'isConcatSpreadable' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(504,5): error TS2687: All declarations of 'iterator' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(510,5): error TS2687: All declarations of 'match' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(516,5): error TS2687: All declarations of 'replace' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(522,5): error TS2687: All declarations of 'search' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(528,5): error TS2687: All declarations of 'species' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(534,5): error TS2687: All declarations of 'split' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(540,5): error TS2687: All declarations of 'toPrimitive' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(546,5): error TS2687: All declarations of 'toStringTag' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(552,5): error TS2687: All declarations of 'unscopables' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(609,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'.
node_modules/@types/core-js/index.d.ts(609,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(613,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'.
node_modules/@types/core-js/index.d.ts(613,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(628,5): error TS2687: All declarations of 'size' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(634,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(645,5): error TS2687: All declarations of 'size' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(651,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(656,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
node_modules/@types/core-js/index.d.ts(664,27): error TS2344: Type 'K' does not satisfy the constraint 'object'.
node_modules/@types/core-js/index.d.ts(665,53): error TS2344: Type 'K' does not satisfy the constraint 'object'.
node_modules/@types/core-js/index.d.ts(666,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(680,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(692,5): error TS2687: All declarations of 'value' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(804,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/typescript/lib/lib.es6.d.ts(4199,14): error TS2300: Duplicate identifier 'PropertyKey'.
将目标更改为es5
导致干净的构建。
我不确定这个问题是如何引起如此少的关注; 肯定很多人都试图用 TS 来瞄准 ES6 并且也会遇到这个问题?
@wyqydsyq core.js 和 ES6 都定义了很多相同的定义。 要么不包含@types/core.js 要么在你的 tsconfig 中设置 "lib": ["es5", "dom"]
我也遇到了类似的冲突。
1>c:\Program Files (x86)\Microsoft SDKs\TypeScript\2.6\lib.es2015.iterable.d.ts(203,11): 错误 TS2300: Build:Duplicate identifier 'Promise'。1>c:\Program Files (x86)\Microsoft SDKs\TypeScript\2.6\lib.es2015.promise.d.ts(223,13): 错误 TS2300: Build:Duplicate identifier 'Promise'。1>c:\Program Files (x86)\Microsoft SDKs\TypeScript\2.6\lib.es2015.symbol.wellknown.d.ts(168,11): 错误 TS2300: Build:Duplicate identifier 'Promise'。1>c:\Program Files (x86)\Microsoft SDKs\TypeScript\2.6\lib.es5.d.ts(1292,11): 错误 TS2300: Build:Duplicate identifier 'Promise'。1>c:\users\username\node_modules\@types\es6-promise\index.d.ts(11,15): 错误 TS2300: Build:Duplicate identifier 'Promise'。1>c:\users\username\node_modules\@types\es6-promise\index.d.ts(42,19): 错误 TS2300: Build:Duplicate identifier 'Promise'。
tsconfig:-
{
“编译器选项”:{
"目标": "es5",
"module": "commonjs",
"moduleResolution": "节点",
"sourceMap": 真,
“emitDecoratorMetadata”:真,
"experimentalDecorators": 真,
"lib": [ "es2015", "dom"],
"noImplicitAny": 真,
"suppressImplicitAnyIndexErrors": true,
"noStrictGenericChecks": 真
}
}
包.Json:
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/common": "~4.3.4",
"@angular/compiler": "~4.3.4",
"@angular/core": "~4.3.4",
"@angular/forms": "~4.3.4",
"@angular/http": "~4.3.4",
"@angular/platform-browser": "~4.3.4",
"@angular/platform-browser-dynamic": "~4.3.4",
"@angular/router": "~4.3.4",
"angular-in-memory-web-api": "~0.3.0",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.8.4"
},
"devDependencies": {
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "2.6.0",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"@types/node": "^6.0.46",
"@types/jasmine": "2.5.36"
},
"repository": {}
}
npm 5.5.1
节点 8.9.1
任何解决方法?
有类似的问题。 在我的tsconfig.json
添加了"skipLibCheck": true
到compilerOptions
tsconfig.json
并且有所帮助
你好
./node_modules/@types/core-js/index.d.ts:1461:36 - 错误 TS2339:类型“SymbolConstructor”上不存在属性“for”。
1461 const_for:typeof core.Symbol.for;
~~~
../node_modules/@types/core-js/index.d.ts:1465:43 - 错误 TS2339: 类型“SymbolConstructor”上不存在属性“hasInstance”。
1465 const hasInstance:typeof core.Symbol.hasInstance;
~~~
../node_modules/@types/core-js/index.d.ts:1469:50 - 错误 TS2339:“SymbolConstructor”类型上不存在“isConcatSpreadable”属性。
第 1469 章
~~~~~~
../node_modules/@types/core-js/index.d.ts:1477:38 - 错误 TS2339:“SymbolConstructor”类型上不存在属性“keyFor”。
第1477章
~~
../node_modules/@types/core-js/index.d.ts:1481:37 - 错误 TS2339:“SymbolConstructor”类型上不存在“匹配”属性。
1481 常量匹配:typeof core.Symbol.match;
~
../node_modules/@types/core-js/index.d.ts:1485:39 - 错误 TS2339:类型“SymbolConstructor”上不存在属性“replace”。
1485 const 替换:typeof core.Symbol.replace;
~~
../node_modules/@types/core-js/index.d.ts:1489:38 - 错误 TS2339:类型“SymbolConstructor”上不存在属性“search”。
1489 常量搜索:typeof core.Symbol.search;
~~
../node_modules/@types/core-js/index.d.ts:1493:39 - 错误 TS2339:“SymbolConstructor”类型上不存在属性“species”。
1493 const 物种:typeof core.Symbol.species;
~~
../node_modules/@types/core-js/index.d.ts:1497:37 - 错误 TS2339:“SymbolConstructor”类型上不存在“split”属性。
1497 const split:typeof core.Symbol.split;
~
../node_modules/@types/core-js/index.d.ts:1501:43 - 错误 TS2339:属性 'toPrimitive' 在类型 'SymbolConstructor' 上不存在。
1501 const toPrimitive: typeof core.Symbol.toPrimitive;
~~~
../node_modules/@types/core-js/index.d.ts:1505:43 - 错误 TS2339:属性 'toStringTag' 在类型 'SymbolConstructor' 上不存在。
1505 const toStringTag: typeof core.Symbol.toStringTag;
~~~
../node_modules/@types/core-js/index.d.ts:1509:43 - 错误 TS2339:“SymbolConstructor”类型上不存在“unscopables”属性。
第 1509 章
~~~
../node_modules/@types/core-js/index.d.ts:2272:36 - 错误 TS2339:类型“SymbolConstructor”上不存在属性“for”。
2272 const_for:typeof core.Symbol.for;
~~~
../node_modules/@types/core-js/index.d.ts:2276:43 - 错误 TS2339: 类型“SymbolConstructor”上不存在属性“hasInstance”。
2276 const hasInstance:typeof core.Symbol.hasInstance;
~~~
../node_modules/@types/core-js/index.d.ts:2280:50 - 错误 TS2339: 类型“SymbolConstructor”上不存在属性“isConcatSpreadable”。
2280 const isConcatSpreadable: typeof core.Symbol.isConcatSpreadable;
~~~~~~
../node_modules/@types/core-js/index.d.ts:2288:38 - 错误 TS2339:“SymbolConstructor”类型上不存在“keyFor”属性。
2288 const keyFor: typeof core.Symbol.keyFor;
~~
../node_modules/@types/core-js/index.d.ts:2292:37 - 错误 TS2339:“SymbolConstructor”类型上不存在“匹配”属性。
2292 常量匹配:typeof core.Symbol.match;
~
../node_modules/@types/core-js/index.d.ts:2296:39 - 错误 TS2339:类型“SymbolConstructor”上不存在属性“replace”。
2296 const 替换:typeof core.Symbol.replace;
~~
../node_modules/@types/core-js/index.d.ts:2300:38 - 错误 TS2339:类型“SymbolConstructor”上不存在属性“search”。
2300 const 搜索:typeof core.Symbol.search;
~~
../node_modules/@types/core-js/index.d.ts:2304:39 - 错误 TS2339:“SymbolConstructor”类型上不存在属性“species”。
2304 const 物种:typeof core.Symbol.species;
~~
../node_modules/@types/core-js/index.d.ts:2308:37 - 错误 TS2339:“SymbolConstructor”类型上不存在“split”属性。
2308 const split:typeof core.Symbol.split;
~
../node_modules/@types/core-js/index.d.ts:2312:43 - 错误 TS2339:属性 'toPrimitive' 在类型 'SymbolConstructor' 上不存在。
2312 const toPrimitive: typeof core.Symbol.toPrimitive;
~~~
../node_modules/@types/core-js/index.d.ts:2316:43 - 错误 TS2339:属性 'toStringTag' 在类型 'SymbolConstructor' 上不存在。
2316 const toStringTag: typeof core.Symbol.toStringTag;
~~~
../node_modules/@types/core-js/index.d.ts:2320:43 - 错误 TS2339:“SymbolConstructor”类型上不存在“unscopables”属性。
2320 const unscopables:typeof core.Symbol.unscoables;
~~~
这是我得到的错误
我的 tsconfig
{
“compileOnSave”:假,
“编译器选项”:{
"baseUrl": "",
"outDir": "./dist/out-tsc",
"sourceMap": 真,
“声明”:假,
“下级迭代”:真,
"experimentalDecorators": 真,
“模块”:“es6”,
"moduleResolution": "节点",
“importHelpers”:真,
"目标": "es5",
“类型根”:[
“节点模块/@types”
],
“库”:[
"es5",
"es2015",
"es2017",
"dom",
“脚本主机”
],
},
“角度编译器选项”:{
“fullTemplateTypeCheck”:真,
"strictInjectionParameters": 真
}
}
帮我解决问题
最有用的评论
有类似的问题。 在我的
tsconfig.json
添加了"skipLibCheck": true
到compilerOptions
tsconfig.json
并且有所帮助