运行打字稿文件显示错误消息为TS2304:找不到名称' PropertyKey' &安培;错误TS2339

时间:2018-05-20 12:24:43

标签: typescript

我正在尝试在Jasmine Framework中运行spec.ts文件,但是在安装@ types / core-js并使用版本0.9.46的以下命令npm i @types/core-js后,会抛出以下错误消息:

>

 ../../node_modules/@types/core-js/index.d.ts(358,34): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(359,34): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(360,61): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(361,60): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(362,65): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(362,97): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(363,60): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(364,58): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(365,59): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(366,58): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(367,61): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(367,117): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(368,42): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(370,81): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(371,78): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(372,76): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(373,73): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(469,59): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(470,59): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(472,48): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(473,69): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(477,40): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(479,48): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(695,55): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(696,45): error TS2304:
> Cannot find name 'PropertyKey'.
> ../../node_modules/@types/core-js/index.d.ts(829,20): error TS2304:
> Cannot find name 'PromiseConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1486,36): error TS2339:
> Property 'for' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1490,43): error TS2339:
> Property 'hasInstance' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1494,50): error TS2339:
> Property 'isConcatSpreadable' does not exist on type
> 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1502,38): error TS2339:
> Property 'keyFor' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1506,37): error TS2339:
> Property 'match' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1510,39): error TS2339:
> Property 'replace' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1514,38): error TS2339:
> Property 'search' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1518,39): error TS2339:
> Property 'species' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1522,37): error TS2339:
> Property 'split' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1526,43): error TS2339:
> Property 'toPrimitive' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1530,43): error TS2339:
> Property 'toStringTag' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(1534,43): error TS2339:
> Property 'unscopables' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2305,36): error TS2339:
> Property 'for' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2309,43): error TS2339:
> Property 'hasInstance' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2313,50): error TS2339:
> Property 'isConcatSpreadable' does not exist on type
> 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2321,38): error TS2339:
> Property 'keyFor' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2325,37): error TS2339:
> Property 'match' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2329,39): error TS2339:
> Property 'replace' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2333,38): error TS2339:
> Property 'search' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2337,39): error TS2339:
> Property 'species' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2341,37): error TS2339:
> Property 'split' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2345,43): error TS2339:
> Property 'toPrimitive' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2349,43): error TS2339:
> Property 'toStringTag' does not exist on type 'SymbolConstructor'.
> ../../node_modules/@types/core-js/index.d.ts(2353,43): error TS2339:
> Property 'unscopables' does not exist on type 'SymbolConstructor'.

1 个答案:

答案 0 :(得分:5)

Use core-js only as a polyfill。不要安装npm i @types/core-js。而是使用tsconfig.json中的lib option

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