Skip to content

Make React types more compatible with other libraries #2282

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

Merged
merged 28 commits into from
Feb 20, 2023

Conversation

thecrypticace
Copy link
Contributor

As a part of this we have done a few things:

  1. Every component now has an explicitly exported PropsComponentNameHere type which is appropriately generic and represents what you can pass to a component's props. Note that this will include props inherited from the component's tag.
  2. We've adjusted the types to "eliminate" the "forward ref-ness" of the component which appears to break things for several components. We now type each component's interface more explicitly while including displayName and enabling inference to continue working (this was way more difficult than it should've been 🙃 )

Fixes #1365
Fixes #1394

@vercel
Copy link

vercel bot commented Feb 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 20, 2023 at 5:24PM (UTC)
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 20, 2023 at 5:24PM (UTC)

@thecrypticace
Copy link
Contributor Author

oh hello wall of red text. Apparently have type errors to track down. 😓

Comment on lines 1278 to 1280
// TODO: One day we will be able to infer this type from the generic in Combobox itself.
// But today is not that day..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random off-topic side note: I think one way we can solve this is by introduce a different API using some factory like functions. Example:

let Combobox = createCombobox<TypeYouWant>()

Which could create the Combobox, Combobox.Input, Combobox.Option, ... components already scoped to the TypeYouWant 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah that's pretty good idea 🤔

Would be a good thing to explore for future improvements

@tomelliot
Copy link

I'm coming from #1394, looking through this commit to try and work out how to use props from a headless UI component.

I was stuck trying to work out what "types" to pass in to the SwitchProps (without any TS gives Generic type 'SwitchProps' requires 1 type argument(s).ts(2314).

For others in the same boat, it looks like we can use the types that are valid for the headless UI component as property. So for a Switch that's button by default, and can be String | Component (from https://headlessui.com/react/switch)

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

Successfully merging this pull request may close these issues.

Export component prop types Prop merging wipes out typing for included HeadlessUI props
3 participants