-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Typing required props for as
#7
Comments
You might have some luck with Typescript's conditional types, but I'm not entirely sure if that'll work. You could also try adding a value for the generic parameter (i.e. props type) of These are just ideas however, so you'd have to do some experimenting on your own. |
Thanks @Mesoptier, I tried your suggestions but wasn't able to get it working with |
@rafgraph I've forked your codesandbox and I think I've figured it out: https://codesandbox.io/s/polymorphic-types-required-props-for-as-forked-fmc7k?file=/src/App.tsx. I added the Edit: the error message is lacking and is not very descriptive, so perhaps there could be some improvements to the types that makes the error message nicer. |
Thanks @Mesoptier, that looks promising! |
@rafgraph Did you manage to get my solution working in your project? |
Hi, is it possible to type the props that
as
is required to accept? Without this it is easy to pass in anas
prop that is not compatible with the polymorphic component. Thanks.Using the heading example in the readme (also see this codesandbox for a live reproduction):
The text was updated successfully, but these errors were encountered: