簡體   English   中英

React打字稿打字不起作用

[英]React typescript typings not working

通過打字安裝后,我在終端中收到以下錯誤

終端錯誤

error TS2320: Interface 'Element' cannot simultaneously extend types 'ReactElement<any>' and 'ReactElement<any>'.
  Named property 'type' of types 'ReactElement<any>' and 'ReactElement<any>' are not identical.

ERROR in /Users/ajvivek/Dev/ES6/motionize-code/typings/globals/react/index.d.ts
(2375,5): error TS1036: Statements are not allowed in ambient contexts.

ERROR in /Users/ajvivek/Dev/ES6/motionize-code/typings/globals/react-dom/index.d.ts
(69,5): error TS2309: An export assignment cannot be used in a module with other exported elements.

ERROR in /Users/ajvivek/Dev/ES6/motionize-code/node_modules/@types/react-dom/index.d.ts
(19,31): error TS2315: Type 'DOMAttributes' is not generic.

ERROR in /Users/ajvivek/Dev/ES6/motionize-code/node_modules/@types/react-dom/index.d.ts
(44,60): error TS2315: Type 'DOMAttributes' is not generic.

ERROR in /Users/ajvivek/Dev/ES6/motionize-code/node_modules/@types/react/index.d.ts
(2368,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'a' must be of type 'HTMLProps<HTMLAnchorElement>', but here has type 'HTMLProps<HTMLAnchorElement>'.

ERROR in /Users/ajvivek/Dev/ES6/motionize-code/node_modules/@types/react/index.d.ts
(2369,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'abbr' must be of type 'HTMLProps<HTMLElement>', but here has type 'HTMLProps<HTMLElement>'.

index.d.ts /// <reference path="globals/react/index.d.ts" /> /// <reference path="globals/react-dom/index.d.ts" />

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "sourceMap": true,
    "noImplicitAny": true,
    "target": "es5",
    "jsx": "react"
  },
  "files": [
    "./app/app.tsx",
    "./app/Hello.tsx",
    "typings/index.d.ts"
  ],
  "exclude": [
      "node_modules"
  ]
}

我已按照https://www.typescriptlang.org/docs/handbook/react-&-webpack.html中提供的文檔進行操作

不確定我錯過了什么?

有人面臨這個問題嗎?

我終於找到了問題。

我接着安裝通過TSD類型一次,然后分型 ,導致重復的分型。

刪除@types文件夾以解決我的問題。

為了防止其他人遇到這種情況,當我的@types/react@types/react-dom軟件包之間出現不匹配時,我也遇到了這個錯誤。 我最后只是刪除了package.json@types/react條目,因為@types/react-dom自動包含它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM