Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error with React.Component<void, void> #15419

Closed
DanHarman opened this issue Apr 27, 2017 · 5 comments
Closed

Type error with React.Component<void, void> #15419

DanHarman opened this issue Apr 27, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@DanHarman
Copy link

DanHarman commented Apr 27, 2017

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?

@aluanhaddad
Copy link
Contributor

Why don't you use React.Component<{}, {}>?

@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2017

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<{}, {}>.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2017

Duplicate of #15409

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 27, 2017
@DanHarman
Copy link
Author

Ok thanks!

@MichaelTontchev
Copy link

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.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants