Skip to content

[TypeScript] List component types don't correctly support render props #7160

@Tbhesswebber

Description

@Tbhesswebber

Expected Behavior

When using the List component in TS with a render prop function as props.children, the types should be correctly inferred, either from an explicit passing of the generic type or inference from the passing of typed data.

Actual Behavior

The types for props.children seem to have been set in such a way that inference expects a union of (((...args: any[]) => Element) & (string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null)) | undefined.

URL, screen shot, or Codepen exhibiting the issue

TS errors when passing a generic
In the current state, it seems that typescript expects a string for the children prop.


TS errors when passing a string as recommended in the above screenshot
When passing a string as recommended above, TypeScript provides a more useful response showing the intersection type expected.

Steps to Reproduce

See screenshots above - PR with fix incoming

Your Environment

  • Grommet version: 2.35.0
  • TypeScript version: 4.9.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypescript enhancements and bugs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions