简体   繁体   English

React打字稿打字不起作用

[英]React typescript typings not working

After installing via typings I get the below error in terminal 通过打字安装后,我在终端中收到以下错误

Terminal error 终端错误

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" /> index.d.ts /// <reference path="globals/react/index.d.ts" /> /// <reference path="globals/react-dom/index.d.ts" />

tsconfig.json 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"
  ]
}

I have followed the documentation provided in https://www.typescriptlang.org/docs/handbook/react-&-webpack.html 我已按照https://www.typescriptlang.org/docs/handbook/react-&-webpack.html中提供的文档进行操作

Not sure what I have missed? 不确定我错过了什么?

Is anyone facing this issue? 有人面临这个问题吗?

I figured out the issue finally. 我终于找到了问题。

I went on to install types once via tsd and then typings that led to duplicate typings. 我接着安装通过TSD类型一次,然后分型 ,导致重复的分型。

Deleted the @types folder to resolve my issue. 删除@types文件夹以解决我的问题。

Just in case anyone else stumbles into this, I also got this error when there was a mismatch between my @types/react and @types/react-dom packages. 为了防止其他人遇到这种情况,当我的@types/react@types/react-dom软件包之间出现不匹配时,我也遇到了这个错误。 I ended up just deleting the @types/react entry in my package.json since it's automatically included by @types/react-dom . 我最后只是删除了package.json@types/react条目,因为@types/react-dom自动包含它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM