React typescript not working

After installation through typing, I get the following error in the 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" />

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 followed the documentation provided at https://www.typescriptlang.org/docs/handbook/react-&-webpack.html

Not sure what I missed?

Anyone facing this problem?

+6
source share
2 answers

I finally figured out the problem.

I continued to set types once through tsd and then typing , which led to duplication of typing.

Delete the @types folder to solve my problem.

+8
source

Just in case, if someone else stumbles about it, I also got this error when there was a mismatch between my @types/react and @types/react-dom . I just deleted the @types/react in my package.json since it automatically turns on @types/react-dom .

+2
source

All Articles