Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In using ReactJS with TypeScript, this error comes up:

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

How do I fix this?

like image 772
bjfletcher Avatar asked Sep 10 '15 15:09

bjfletcher


1 Answers

The P is the props type and the S is the state type. You'll want to change:

class MyComponent extends React.Component { ...

to:

interface MyProps {}
interface MyState {}

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

Then expand the MyProps and MyState interfaces to include typing for all the props and state that the component needs.

like image 65
bjfletcher Avatar answered Oct 22 '22 01:10

bjfletcher