Typescript вызывает ошибки, когда у меня есть зависимость npm, которая добавляет @ types / core-js в node_modules - PullRequest
0 голосов
/ 24 апреля 2019

UPDATE Я понял это с этим вопросом: https://github.com/Microsoft/TypeScript/issues/9731

"types": [],

и используя это для моего глотка: https://www.typescriptlang.org/docs/handbook/gulp.html

-

Я хочу скомпилировать test.ts или проект, в котором у меня есть backstopjs в node_modules. У этого репозитория есть зависимость chrome-launcher@0.10.5, которая добавляет core-js в папку @ types / core-js.

Это вызывает у меня проблемы при компиляции Typscript:

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 или удаление проблемной папки. Оба варианта не работают для меня, потому что мне нужно, чтобы он был совместим со старыми браузерами.

Есть ли способ сообщить typcript: игнорировать @ types / core-js, чтобы я не получил никаких ошибок, потому что мне нужна обратная остановка в качестве зависимости.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...