Skip to content

Bug: Constraining children to type has no effect #27545

@speculees

Description

@speculees

I need to set a constraint on parent component, so only children of certain type are allowed. Maybe this is intended behavior, but if so how do you set constraint?

React version: 18.2.0

Steps To Reproduce

  1. Create a component with children property and use generic type React.ReactElement

    to constrain what children are allowed to be passed

  2. Observe that you can still add any child as if React.ReactElement is used

Link to code example: https://codesandbox.io/s/react-typescript-forked-wzkkvl?file=/src/App.tsx

The current behavior

Allows the children of parent to be of any type

The expected behavior

Parent component should be marked with error "Types of property 'children' are incompatible." if other component is passed as child

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions