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

Q: How to extend types and spread props #5

Open
georgewrmarshall opened this issue Jun 12, 2023 · 1 comment
Open

Q: How to extend types and spread props #5

georgewrmarshall opened this issue Jun 12, 2023 · 1 comment

Comments

@georgewrmarshall
Copy link

georgewrmarshall commented Jun 12, 2023

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!

@georgewrmarshall georgewrmarshall changed the title Q: How to extend types to Q: How to extend types and spread props Jun 12, 2023
@georgewrmarshall
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant