2017-08-02 54 views
6

我已經安裝@ types/react-dom以及typescript和@ types/react和@ types/meteor,但是當我嘗試從命令行運行typechecker時,出現以下錯誤node_modules/@ types/react-dom/....中的錯誤後續變量聲明必須具有相同的類型。變量'a'

您可以重現錯誤,並看到我所有的配置在這裏:https://github.com/Falieson/react15-meteor1.5

感謝您的幫助!

$ meteor npm run type:client 

> [email protected] 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" 
    } 
} 

回答

4

的類型陣營16測試已出版爲 '最新' 陣營類型。

新版本刪除React 16中已刪除的部分(如React.DOM)的定義,這是預期的。

不幸的是,這些類型的React 16測試版的發佈是在npm而不是@next(就像React那樣)中@latest(默認)標記完成的。

我有一個開放的問題(#18708)與DefinitelyTyped這裏:https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18708

你可以嘗試專門針對特定版本(npm install --save @types/[email protected]),但在@類型的依賴性/反應-DOM爲@類型/反應設置到「*」,這似乎導致@ types/react @ latest仍然被下載,導致您在node_modules目錄的各個位置有多個版本。

我們不得不做一些手動工作來解決這個問題。希望維護@ types/react的人們很快就會解決這個問題。

0

我使用的紗線,並通過運行rm -rf node_modules && rm yarn.lock && yarn install

+0

固定這只是讓人們都知道 - 如果你是依靠紗作爲包管理器,則該命令破壞yarn'的'的全部目的。雖然它肯定解決了這個問題:)另一方面,你可以直接運行'npm install' – Dethariel

相關問題