twc
twc copied to clipboard
Infer types automatically based on HTML element or React component
Summary
- Infer types automatically based on HTML element or React component
- Stop overriding element props when defining custom props
Instead of:
tw.div<TwcComponentProps<'div'> & { $custom: string }>(...)
tw(Link)<LinkProps & $custom: string>(...)
Simply use:
tw.div<{ $custom: string }>(...)
twc(Link)<{ $custom?: boolean }>(...)
Test plan
@irangarcia is attempting to deploy a commit to the Argos CI Team on Vercel.
A member of the Team first needs to authorize it.
Hi @irangarcia, with your system, how do you restrict props to be passed to your component? I think your system is less flexible than the original one right?
@gregberge First, I want to say thank you for the twc I love it <3.
Then, what @irangarcia is proposing here you are going to get with the following explanation:
Here is how this works fine but without custom styling:
If we need to add a custom property to change classes based on behavior we get the following TS Issue (looks like IntrinsicAttributes is not well detected, could be a TS version issue? did you experience the same while using it?): "Type '{ children: string; href: string; $isDisabled: true; }' is not assignable to type 'IntrinsicAttributes & { $isDisabled?: boolean | undefined; }'. Property 'children' does not exist on type 'IntrinsicAttributes & { $isDisabled?: boolean | undefined; }'.ts(2322)"
To solve it, we must specify the props including the current component ones plus extending the required.
In conclusion, what Iran wanted to do is to automatically infer the native component props, instead to be adding every time the extended ones (doesn't matter if we are talking about the forwarded to the component or not).
I'm clear about the issue. How do I collaborate?
@irangarcia I feel that we shouldn't change the tests, I mean, you can create new ones but not modify current ones to avoid missing adding a new issue, including retro-compatibility, if the people are manually adding we need to concatenate them. What do you think @gregberge?
Thanks a lot!
I prefer to keep it explicit as it is in the current version.