简体   繁体   English

“xxx”类型缺少“ElementClass”类型的以下属性:context、setState、forceUpdate、props 和另外 2 个。 TS2605

[英]Type 'xxx' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, and 2 more. TS2605

I'm receiving the following error when trying to run my react app:尝试运行我的反应应用程序时收到以下错误:

D:/React/my-components/src/App.tsx TypeScript error in D:/React/my-components/src/App.tsx(23,4): JSX element type 'Confirm' is not a constructor function for JSX elements. D:/React/my-components/src/App.tsx TypeScript D:/React/my-components/src/App.tsx(23,4) 中的错误:JSX 元素类型“确认”不是 JSX 的构造函数 function元素。 Type 'Confirm' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, and 2 more. “确认”类型缺少“ElementClass”类型的以下属性:上下文、setState、forceUpdate、props 和另外 2 个。 TS2605 TS2605

21 |         </a>
22 |       </header>
23 |      <Confirm />
   |      ^
24 |     </div>
25 |   );
26 | }

Here is my Confirm component code这是我的确认组件代码

 import * as React from "react"; class Confirm extends React.Component{ render(){ return ( <div className="confirm-wrapper confirm-visible"> <div className="confirm-container"> <div className="confirm-title-container"> <span>This is where our title should go</span> </div> <div className="confirm-content-container"> <p>This is where our content should go</p> </div> <div className="confirm-buttons-container"> <button className="confirm-cancel">Cancel</button> <button className="confirm-ok">Okay</button> </div> </div> </div> ); } } export default Confirm;

And App.tsx code和 App.tsx 代码

 import React from 'react'; import logo from './logo.svg'; import './App.css'; import Confirm from './Confirm'; const App: React.FC = () => { return ( <div className="App"> <header className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <p> Edit <code>src/App.tsx</code> and save to reload. </p> <a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer" > Learn React </a> </header> <Confirm /> </div> ); } export default App;

This is my package.json这是我的 package.json

 { "name": "my-components", "version": "0.1.0", "private": true, "dependencies": { "@types/jest": "24.0.18", "@types/node": "12.7.8", "@types/react": "16.9.4", "@types/react-dom": "16.9.1", "react-scripts": "3.1.2", "typescript": "3.6.3" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": "react-app" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "react": "^16.10.1", "react-dom": "^16.10.1", "tslint": "^5.20.0", "tslint-config-prettier": "^1.18.0", "tslint-react": "^4.1.0" } }

Thank all, i have fixed this error by run following command谢谢大家,我已经通过运行以下命令修复了这个错误

yarn upgrade @types/react@latest纱线升级@types/react@latest

I had a component named Component.tsx (camelcase) and a helper called component.ts (lowercase) and this seemed to make these become mixed up.我有一个名为Component.tsx (驼峰式)的组件和一个名为component.ts (小写)的助手,这似乎使这些变得混淆了。 I was importing them in the same file also so I just renamed the Component one.我也在同一个文件中导入它们,所以我只是重命名了组件之一。

暂无
暂无

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

相关问题 类型“Element”缺少类型“OfferProps”中的以下属性:id、firstName、city、price 和另外 2 个。 TS2740 - Type 'Element' is missing the following properties from type 'OfferProps': id, firstName, city, price, and 2 more. TS2740 React:在TS组件中使用ES6组件:TS2605:JSX元素类型&#39;xxx&#39;不是JSX元素的构造函数 - React: Using ES6 component in TS component: TS2605: JSX element type 'xxx' is not a constructor function for JSX elements REACT Typescript fetch/axios 错误 - 来自“地址 []”类型的以下属性:长度、弹出、推送、连接和另外 28 个。 TS2740 - REACT Typescript fetch/ axios error - following properties from type 'Address[]': length, pop, push, concat, and 28 more. TS2740 (TS) 类型“{}”缺少类型中的以下属性 - (TS) Type '{}' is missing the following properties from type “上下文”类型缺少“上下文”类型的以下属性<unknown> &#39;:提供者、消费者 TS2345 - Type 'Context' is missing the following properties from type 'Context<unknown>': Provider, Consumer TS2345 使用 useContext、ureReducer 和 useMemo 做出反应:XXX 缺少 YYY TS2739 类型错误中的以下属性 - React using useContext, ureReducer and useMemo: XXX is missing the following properties from type YYY TS2739 error TS 错误:“事件”类型缺少“键盘事件”类型中的以下属性 - TS error: Type 'event' is missing the following properties from type 'keyboardevent' 类型“{}”缺少类型 ts(2739) 中的以下属性 - Type '{}' is missing the following properties from type ts(2739) TS2739 - 以下属性中缺少类型 - TS2739 - Type missing in following properties 将React Component作为参数时,“ Type缺少以下属性,上下文,setState” - “Type is missing the following properties, context, setState” when having React Component as argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM