Skip to content

[@types/react] PropsWithChildren is incorrect or misleading. #40993

@joshmanders

Description

@joshmanders

If you know how to fix the issue, make a pull request instead.


I prefer to be explicit with my types, and I noticed something, that all components, at least functional ones that use React.FC or React.FunctionComponent have a generic that unionizes with PropsWithChildren that automatically adds { children?: ReactNode } and I feel that is incorrect or misleading.

Given a component that does not accept or use children that prop should not be present, right? It's not passed by React at all. Example shown in screenshot below. So why is it given as a potential prop default on all component types?

I feel this defeats the purpose of types. TypeScript should technically give an error if you did <Foo>hi</foo> and <Foo /> never used the children prop.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions