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

'children' is missing in props validation(react/prop-types) when using React.PropsWithChildren as of 7.25.0 #3062

Closed
FritsvanCampen opened this issue Aug 30, 2021 · 8 comments

Comments

@FritsvanCampen
Copy link

FritsvanCampen commented Aug 30, 2021

When you have a typescript component like:

const MyComponent = (props: React.PropsWithChildren<{}>): React.ReactElement => {
	return <>{props.children}</>;
};

As of 7.25 you get the warning:

'children' is missing in props validation(react/prop-types)

React.PropsWithChildren is defined as:

type PropsWithChildren<P> = P & { children?: ReactNode | undefined };

If you change the Component props type to:

const MyComponent = (props: React.PropsWithChildren<{ children?: ReactNode | undefined }>): React.ReactElement => {
	return <>{props.children}</>;
};

The warning disappears.

I believe this is a mistake. The warning should not trigger in both cases.
It did not trigger in 7.24. It does as of 7.25.

@ljharb
Copy link
Member

ljharb commented Aug 30, 2021

cc @vedadeepta

@vedadeepta
Copy link
Contributor

Will look into it

@johnhunter
Copy link

I'm seeing the same with React.FC when upgrading from 7.24.0 to 7.25.0

@vedadeepta
Copy link
Contributor

vedadeepta commented Aug 31, 2021

@johnhunter the PR fixes React.FC also
this should work from the next release, apologies for the inconvenience

          import React from 'react';
          const Person: React.FC<{}> = (props): React.ReactElement => (
              <>{props.children}</>
          );

@ljharb
Copy link
Member

ljharb commented Aug 31, 2021

Fixed in #3064, which will be released soon.

@ljharb ljharb closed this as completed Aug 31, 2021
@FritsvanCampen
Copy link
Author

Thanks for the quick fix!

@johnhunter
Copy link

I still see 'children' is missing in props validation react/prop-types using React.FC with v7.25.1

@ljharb
Copy link
Member

ljharb commented Sep 6, 2021

@johnhunter you’ll see that for eternity, since that version doesn’t contain the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants