更新 我想出了这个问题: https://github.com/Microsoft/TypeScript/issues/9731
"types": [],
并将其用于我的口吃: https://www.typescriptlang.org/docs/handbook/gulp.html
-
我想在一个在node_modules中有backstopjs的项目中编译test.ts。该仓库具有独立的chrome-launcher@0.10.5,可将core-js添加到文件夹@ types / core-js。
这使我在编译打字稿时遇到问题:
Package.json
{
"name": "backstop-typescript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"backstopjs": "^3.8.8"
}
}
这是我的文件:
function greeter(person) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.innerHTML = greeter(user);
这是我正在运行的命令:
tsc test.ts
这是它引起的错误:
829 const Promise: PromiseConstructor;
~~~~~~~~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:1486:36 - error TS2339: Property 'for' does not exist on type 'SymbolConstructor'.
1486 const _for: typeof core.Symbol.for;
~~~
node_modules/@types/core-js/index.d.ts:1490:43 - error TS2339: Property 'hasInstance' does not exist on type 'SymbolConstructor'.
1490 const hasInstance: typeof core.Symbol.hasInstance;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:1494:50 - error TS2339: Property 'isConcatSpreadable' does not exist on type 'SymbolConstructor'.
1494 const isConcatSpreadable: typeof core.Symbol.isConcatSpreadable;
~~~~~~~~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:1502:38 - error TS2339: Property 'keyFor' does not exist on type 'SymbolConstructor'.
1502 const keyFor: typeof core.Symbol.keyFor;
~~~~~~
node_modules/@types/core-js/index.d.ts:1506:37 - error TS2339: Property 'match' does not exist on type 'SymbolConstructor'.
1506 const match: typeof core.Symbol.match;
~~~~~
node_modules/@types/core-js/index.d.ts:1510:39 - error TS2339: Property 'replace' does not exist on type 'SymbolConstructor'.
1510 const replace: typeof core.Symbol.replace;
~~~~~~~
node_modules/@types/core-js/index.d.ts:1514:38 - error TS2339: Property 'search' does not exist on type 'SymbolConstructor'.
1514 const search: typeof core.Symbol.search;
~~~~~~
node_modules/@types/core-js/index.d.ts:1518:39 - error TS2339: Property 'species' does not exist on type 'SymbolConstructor'.
1518 const species: typeof core.Symbol.species;
~~~~~~~
node_modules/@types/core-js/index.d.ts:1522:37 - error TS2339: Property 'split' does not exist on type 'SymbolConstructor'.
1522 const split: typeof core.Symbol.split;
~~~~~
node_modules/@types/core-js/index.d.ts:1526:43 - error TS2339: Property 'toPrimitive' does not exist on type 'SymbolConstructor'.
1526 const toPrimitive: typeof core.Symbol.toPrimitive;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:1530:43 - error TS2339: Property 'toStringTag' does not exist on type 'SymbolConstructor'.
1530 const toStringTag: typeof core.Symbol.toStringTag;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:1534:43 - error TS2339: Property 'unscopables' does not exist on type 'SymbolConstructor'.
1534 const unscopables: typeof core.Symbol.unscopables;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:2305:36 - error TS2339: Property 'for' does not exist on type 'SymbolConstructor'.
2305 const _for: typeof core.Symbol.for;
~~~
node_modules/@types/core-js/index.d.ts:2309:43 - error TS2339: Property 'hasInstance' does not exist on type 'SymbolConstructor'.
2309 const hasInstance: typeof core.Symbol.hasInstance;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:2313:50 - error TS2339: Property 'isConcatSpreadable' does not exist on type 'SymbolConstructor'.
2313 const isConcatSpreadable: typeof core.Symbol.isConcatSpreadable;
~~~~~~~~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:2321:38 - error TS2339: Property 'keyFor' does not exist on type 'SymbolConstructor'.
2321 const keyFor: typeof core.Symbol.keyFor;
~~~~~~
node_modules/@types/core-js/index.d.ts:2325:37 - error TS2339: Property 'match' does not exist on type 'SymbolConstructor'.
2325 const match: typeof core.Symbol.match;
~~~~~
node_modules/@types/core-js/index.d.ts:2329:39 - error TS2339: Property 'replace' does not exist on type 'SymbolConstructor'.
2329 const replace: typeof core.Symbol.replace;
~~~~~~~
node_modules/@types/core-js/index.d.ts:2333:38 - error TS2339: Property 'search' does not exist on type 'SymbolConstructor'.
2333 const search: typeof core.Symbol.search;
~~~~~~
node_modules/@types/core-js/index.d.ts:2337:39 - error TS2339: Property 'species' does not exist on type 'SymbolConstructor'.
2337 const species: typeof core.Symbol.species;
~~~~~~~
node_modules/@types/core-js/index.d.ts:2341:37 - error TS2339: Property 'split' does not exist on type 'SymbolConstructor'.
2341 const split: typeof core.Symbol.split;
~~~~~
node_modules/@types/core-js/index.d.ts:2345:43 - error TS2339: Property 'toPrimitive' does not exist on type 'SymbolConstructor'.perty 'toPrimitive' does not exist on type 'SymbolConstructor'.
2345 const toPrimitive: typeof core.Symbol.toPrimitive;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:2349:43 - error TS2339: Property 'toStringTag' does not exist on type 'SymbolConstructor'.
2349 const toStringTag: typeof core.Symbol.toStringTag;
~~~~~~~~~~~
node_modules/@types/core-js/index.d.ts:2353:43 - error TS2339: Property 'unscopables' does not exist on type 'SymbolConstructor'.
2353 const unscopables: typeof core.Symbol.unscopables;
~~~~~~~~~~~
Found 25 errors.
我尝试使用这些选项添加tsconfig.json
{
"compilerOptions": {
"skipLibCheck": true
},
"exclude": ["node_modules/"]
}
通过执行以下命令:
tsc -p test.ts
它不起作用。
我发现删除错误的唯一解决方案是将其更改为es2015或删除有问题的文件夹。这两种方法都不适合我,因为我需要与旧版浏览器兼容。
有没有办法告诉打字稿:忽略@ types / core-js,所以我没有得到任何错误,因为我需要使用backstop作为依赖。