Typescript typings.d.ts не работает с ошибкой синтаксического анализа - PullRequest
0 голосов
/ 17 июня 2020

Когда я запускаю lint, мой машинописный код выдает ошибку синтаксического анализа:

  2:3  error  Parsing error: Only declares and type imports are allowed inside declare module

  1 | declare module "*.json" {
> 2 |   var value: any;
    |   ^
  3 |   export default value;
  4 | }

Я новичок в TypeScript и действительно не уверен, как это исправить?

Мой tsconfig выглядит как следует:

{
  "compilerOptions": {
    "isolatedModules": true,  // Warn you if you write certain code that can’t be correctly interpreted by a single-file transpilation process.
    "outDir": "./dist/",
    "module": "commonjs",
    "target": "ES5",
    "jsx": "react",
    "lib": ["ESNEXT", "DOM", "DOM.Iterable", "ES5"],
    "allowJs": true, // Allow JavaScript files to be imported inside your project, instead of just .ts and .tsx
    "checkJs": true,  // When checkJs is enabled then errors are reported in JavaScript files. This is the equivalent of including // @ts-check at the top of all JavaScript files which are included in your project.
    "allowSyntheticDefaultImports": true, // Allow default imports from modules with no default export
    "skipLibCheck": true,
    "types": ["node", "webpack-env", "@wdio/sync", "mocha", "expect-webdriverio"],
    "strict": false // Enables all strict type checking options (This is too restrictive for the current code base)
  },
  "include": [
    "src/**/**.ts",
    "test/**/**.ts"
  ]
}

Следует ли мне его исключить? Это база кода React с Webpack.

1 Ответ

1 голос
/ 17 июня 2020
error  Parsing error: Only declares and type imports are allowed inside declare module

Ответ кроется в самой ошибке.

declare module - это объявление типов, но то, что вы делаете в своем коде, определяет переменную ( значение, а не тип), поэтому это просто недопустимо и тоже не имеет смысла. Просто удалите эту строку, и ошибка будет go.

Если бы вы могли сказать, чего на самом деле пытаетесь достичь, мы могли бы вам в этом помочь.

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