Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Typescript typings.d.ts因分析错误而失败_Reactjs_Typescript_Webpack_Typescript Typings - Fatal编程技术网

Reactjs Typescript typings.d.ts因分析错误而失败

Reactjs Typescript typings.d.ts因分析错误而失败,reactjs,typescript,webpack,typescript-typings,Reactjs,Typescript,Webpack,Typescript Typings,当我运行lint我的typescript代码时,它抛出一个解析错误: 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

当我运行lint我的typescript代码时,它抛出一个解析错误:

  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还不熟悉,真的不知道如何解决这个问题

我的配置如下:

{
  "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"
  ]
}
我应该排除它吗?这是一个带有Web包的React代码库

error  Parsing error: Only declares and type imports are allowed inside declare module
答案在于错误本身

declare模块
用于声明类型,但您在代码中所做的是定义一个变量(值而不是类型),因此它是不允许的,也没有意义。只需删除该行,错误就会消失

如果你能说出你真正想要达到的目标,我们可以帮你