【问题标题】:Error at node_modules/@types/react-dom/.... Subsequent variable declarations must have the same type. Variable 'a'node_modules/@types/react-dom/.... 的错误。后续的变量声明必须具有相同的类型。变量“a”
【发布时间】:2018-01-10 03:24:51
【问题描述】:

我已经安装了 @types/react-dom 以及 typescript 和 @types/react 和 @types/meteor 但是当我尝试从命令行运行 typechecker 时出现以下错误

您可以在此处重现错误并查看我的所有配置:https://github.com/Falieson/react15-meteor1.5

感谢您的帮助!

$ meteor npm run type:client

> react-meteor-example@0.1.0 type:client /Users/sjcfmett/Private/ReactMeteorExample
> tslint -p ./tsconfig.json --type-check './client/**/*.{ts,tsx}'

Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3422:13: Subsequent variable declarations must have the same type.  Variable 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.
Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3423:13: Subsequent variable declarations must have the same type.  Variable 'abbr' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3424:13: Subsequent variable declarations must have the same type.  Variable 'address' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3425:13: Subsequent variable declarations must have the same type.  Variable 'area' must be of type 'DetailedHTMLProps<AreaHTMLAttributes<HTMLAreaElement>, HTMLAreaElement>', but here has type 'DetailedHTMLProps<AreaHTMLAttributes<HTMLAreaElement>, HTMLAreaElement>'.
... (shortened)

package.json(供参考)

{
  "name": "react-meteor-example",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "meteor run",
    "lint:client": "tslint --fix -c ./tslint.json -p ./tsconfig.json './client/**/*.{ts,tsx}'",
    "lint:imports": "tslint --fix -c ./tslint.json -p ./tsconfig.json './imports/**/*.{ts,tsx}'",
    "lint:server": "tslint --fix -c ./tslint.json -p ./tsconfig.json './server/**/*.ts'",
    "lint": "npm run lint:client && npm run lint:server && npm run lint:imports",
    "type:imports": "tslint -p ./tsconfig.json --type-check './imports/**/*.{ts,tsx}'",
    "type:client": "tslint -p ./tsconfig.json --type-check './client/**/*.{ts,tsx}'",
    "type:server": "tslint -p ./tsconfig.json --type-check './server/**/*.ts'",
    "type": "npm run type:client && npm run type:server && npm run type:imports",
    "precommit": "npm run lint && npm run type"
  },
  "dependencies": {
    "babel-runtime": "^6.20.0",
    "meteor-node-stubs": "~0.2.4",
    "react": "^15.6.1",
    "react-dom": "^15.6.1"
  },
  "devDependencies": {
    "@types/meteor": "^1.4.2",
    "@types/react": "^15.6.0",
    "@types/react-dom": "^15.5.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "husky": "^0.14.3",
    "tslint": "^5.5.0",
    "tslint-react": "^3.1.0",
    "typescript": "^2.4.2"
  }
}

【问题讨论】:

    标签: reactjs typescript meteor typescript-typings react-dom


    【解决方案1】:

    React 16 beta 的类型已作为“最新”的 React 类型发布。

    新版本移除了 React 16 中已移除的部分定义(如 React.DOM),这是意料之中的。

    不幸的是,这些类型的 React 16 beta 发布是在 npm 中的 @latest(默认)标签上完成的,而不是 @next(就像 React 所做的那样)。

    我有一个未解决的问题 (#18708),这里是“DefiniteTyped”:https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18708

    您可以尝试专门针对特定版本 (npm install --save @types/react@15.6.0),但 @types/react-dom 中 @types/react 的依赖项设置为“*”,这似乎导致 @types/react@latest 仍然被下载,导致您在 node_modules 目录的不同位置有多个版本。

    我们不得不做一些手动工作来解决这个问题。希望维护@types/react 的人能尽快解决这个问题。

    【讨论】:

      【解决方案2】:

      我正在使用 yarn,并通过运行 rm -rf node_modules &amp;&amp; rm yarn.lock &amp;&amp; yarn install 解决了这个问题

      【讨论】:

      • 只是为了让人们意识到——如果你依赖 yarn 作为包管理器,那么这个命令就破坏了yarn 的全部目的。虽然它确实解决了这个问题 :) 另一方面,你可以运行 npm install 来代替
      猜你喜欢
      • 1970-01-01
      • 2016-11-07
      • 2017-11-15
      • 2018-04-18
      • 2019-09-04
      • 1970-01-01
      • 2020-01-03
      • 2017-07-14
      • 2016-04-11
      相关资源
      最近更新 更多