Skip to content

Q: How to extend types and spread props #5

Open

Description

@georgewrmarshall

Hello, Thanks providing such a helpful example. It has greatly assisted me in the process of migrating our components that utilize polymorphic props from JavaScript to TypeScript. Specifically, our components rely on a Box component as a child, which contains style utility props such as margin and padding. I'm interested in understanding how I can extend this pattern to all of our components.

To illustrate the issue, I have created a CodeSandbox environment https://codesandbox.io/s/polymorphic-prop-type-q4pwvl?file=/src/text.tsx:622-888

In the above example I am trying to use the Box component that has the polymorphic as prop as the base for the Text component that can also forward refs, enables correct polymorphic typing but has extra logic that the Box doesn't need. I'm not sure my types are quite right or if I'm over complicating them? Any suggestions would be greatly appreciated!

Activity

  1. changed the title [-]Q: How to extend types to [/-] [+]Q: How to extend types and spread props[/+] on Jun 12, 2023
  2. georgewrmarshall commented on Jun 12, 2023

    @georgewrmarshall
    Author

    It also seems that I need to update the types for the Box component so it accepts spreading props?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions