reactjs - 错误 TS2314 : Generic type 'Component<P, S>' requires 2 type argument(s)

标签 reactjs typescript

在将 ReactJS 与 TypeScript 一起使用时,出现此错误:

error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).

我该如何解决这个问题?

最佳答案

P 是 Prop 类型,S 是状态类型。你会想要改变:

class MyComponent extends React.Component { ...

到:

interface MyProps {}
interface MyState {}

class MyComponent extends React.Component<MyProps, MyState> { ...

然后扩展 MyPropsMyState 接口(interface)以包含组件所需的所有 Prop 和状态的类型。

关于reactjs - 错误 TS2314 : Generic type 'Component<P, S>' requires 2 type argument(s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32506180/

相关文章:

angular - 无法在 Ionic 3 上创建路线

properties - 没有 setter 的属性的 TypeScript 接口(interface)签名。

javascript - 在 React 组件生命周期中什么时候可以执行路由更改?

javascript - 具有分页意外结果的 React-Table 排序

javascript - react-fullpage - 避免渲染中的 setState 无限循环

angular - 在 Angular 中调用具有依赖关系的函数

reactjs - 如何在 React 中的 onClick 之后测试 next/link (Nextjs) 获取页面重定向?

css - React 导入图像不适用于 CSS

angular - 我的表单未找到值并且始终检查滑动切换

Angular 2 : Chain Observables in Resolver