javascript - react typescript 打字不起作用

标签 javascript reactjs typescript webpack typescript-typings

通过打字安装后,我在终端中收到以下错误

终端错误

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 安装类型,然后 typings 导致重复输入。

删除了 @types 文件夹以解决我的问题。

关于javascript - react typescript 打字不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39992690/

相关文章:

javascript - Masonry & LazyLoad 不想一起工作

reactjs - 什么时候派生数据对于 redux 选择器来说过于复杂?

reactjs - 尝试在 .map 调用期间更改我的数据

javascript正则表达式替换html

javascript - IE8 的音频标签替代方案

reactjs - 如何重命名由 create react app 创建的文件夹?

javascript - 为什么我不能使用 setState 将对象传递给状态?

javascript - TypeScript 扩展第三方库 moment.js

node.js - TypeScript、MongoDB 和引用问题

javascript - 如何在 Chrome 的开发者工具中按主机和端口进行过滤?