TypeScript Version: 2.3.1
Code
export class NavMenu extends React.Component<void, void> {...}
<NavMenu />
Expected behavior:
It doesn't give a type error.
Actual behavior:
At the location the component is instantiated:
TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<NavMenu> & { children?: ReactNode; } & void'.
Type '{}' is not assignable to type 'void'.
This could be a typings error perhaps, but it seems wrong to have to create a functional component to not have any props, or have to make the props type undefined?
Why don't you use React.Component<{}, {}>?
as @aluanhaddad noted, void for props does not make much sense. props will always be there at run time and it will be an object. it should React.Component<{}, {}>.
Duplicate of https://github.com/Microsoft/TypeScript/issues/15409
Ok thanks!
Just ran into this same issue after updating. Thanks!
Side note: I thought it was standard to use "void" as the state/props type when they don't exist. My guess is a lot of people will have broken builds when they upgrade.
Most helpful comment
Just ran into this same issue after updating. Thanks!
Side note: I thought it was standard to use "void" as the state/props type when they don't exist. My guess is a lot of people will have broken builds when they upgrade.