twc icon indicating copy to clipboard operation
twc copied to clipboard

Infer types automatically based on HTML element or React component

Open irangarcia opened this issue 8 months ago • 3 comments

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 avatar Mar 11 '25 16:03 irangarcia

@irangarcia is attempting to deploy a commit to the Argos CI Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Mar 11 '25 16:03 vercel[bot]

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 avatar Mar 15 '25 07:03 gregberge

@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: image

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)"

Screenshot 2025-03-17 at 5 39 01 PM

To solve it, we must specify the props including the current component ones plus extending the required. image

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!

santinozaracho avatar Mar 17 '25 20:03 santinozaracho

I prefer to keep it explicit as it is in the current version.

gregberge avatar Jun 30 '25 16:06 gregberge