I've seen multiple examples of React components using Typescript:
class Foo extends React.Component<IProps, IState> {}
It seems there is no a clear convention when we don't use either the Props or the State.
People set these types as any
, null
,undefined
,{}
, , etc.This is what I've seen so far:void
class Foo extends React.Component<null, null> {}
class Foo extends React.Component<any, any> {}
class Foo extends React.Component<{}, {}> {}
class Foo extends React.Component<undefined, undefined> {}
class Foo extends React.Component<void, void> {}
class Foo extends React.Component<object, object> {}
What's the best way of doing it?
Update:
Props:
void
cannot be used (https://github.com/Microsoft/TypeScript/issues/15409 and https://github.com/Microsoft/TypeScript/issues/15419 ) as the props object is initialised to{}
SOLUTION
Simply do - class Foo extends React.Component {}
as prop and state are initialised to {}