Ricerca nel sito web

reactjs - Errore in node_modules/@types/react-dom/.... Le dichiarazioni successive di variabile devono avere lo stesso tipo. Variabile 'a'


Ho installato @types/react-dom insieme a typescript e @types/react e @types/meteor, ma quando provo a eseguire il typechecker da linea di comando ricevo il seguente errore

Puoi riprodurre l'errore e vedere tutta la mia configurazione qui: https://github.com/Falieson/react15-meteor1.5

Grazie per il tuo aiuto!

meteor npm run type:client

> [email  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 (per riferimento)

{
  "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"
  }
}

Risposta n. 1

I tipi per React 16 beta sono stati pubblicati come i tipi React 'latest'.

La nuova versione rimuove le definizioni per le parti di React che sono state rimosse in React 16 (come React.DOM), il che è previsto.

Purtroppo, la pubblicazione di questi tipi per la beta di React 16 è stata fatta con il tag @latest (predefinito) in npm invece che con @next (come ha fatto React).

Ho una questione aperta (#18708) con DefinitelyTyped qui: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18708

Puoi provare a mirare specificamente a una versione particolare (npm install --save @types/[email ), ma le dipendenze in @types/react-dom per @types/react sono impostate su "*", il che sembra causare comunque il download di @types/react@latest, causando la presenza di più versioni in diversi punti della tua directory node_modules.

Stiamo dovendo fare un po' di lavoro manuale per risolvere questo problema. Speriamo che le persone che mantengono @types/react lo risolvano presto.

Risposta n. 2

Sto usando yarn e ho risolto questo eseguendo rm -rf node_modules && rm yarn.lock && yarn install

Articoli correlati