Export component prop types
See original GitHub issueWhat package within Headless UI are you using?
What version of that package are you using?
v1.5.0
What browser are you using?
N/A
Reproduction URL
N/A
Describe your issue
In React + Typescript, a common pattern I follow is to wrap a library component for styling or custom behaviour before exposing it to the rest of the codebase. I like to mirror the underlying component props so that Typescript intellisense can provide the same prop hints to for the wrapper component as the underlying library component.
Here is an example of what I want:
// Wrapping a tab for custom styling. TabProps, however, does not exist;
function TemplateLibraryTab({ children, ...props }: TabProps) {
return (
<Tab
{...props}
className={({ selected }) =>
clsx("p-2 rounded", selected ? "text-gray-900" : "text-gray-500")
}
>
{children}
</Tab>
)
}
HeadlessUI does not seem to expose these props, or at least I could not find them. Would it be possible to export these prop types for this purpose? I think it is a strong use-case.
Issue Analytics
- State:
- Created a year ago
- Reactions:44
- Comments:15
Top Results From Across the Web
Typechecking With PropTypes - React
PropTypes exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're...
Read more >Export prop types as TypeScript types in published JavaScript ...
I have a React component authored in JavaScript and published to an npm repository. This component uses the prop-types library to do runtime ......
Read more >TypeScript Tips: Getting Component Props Types in React
Now, to fix this, one could export the UI component props types and use it from the HoC component. And, that works well...
Read more >React Pattern: Centralized PropTypes - freeCodeCamp
I use a named import to get a reference to the exported PropType declaration on line 2. And I put it to use...
Read more >Notes on TypeScript: Accessing Non Exported Component ...
Sometimes we need to access some component prop types, but they have not been exported. Then there are also cases where we would...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks to discussions/601, I got it working like this:
You may also need to do something like this if you want the nested components to work too.
Yup for some reason it broke now.
Type '(<TTag extends ElementType<any> = "button">(props: Props<TTag, TabRenderPropArg, TabPropsWeControl>, ref: Ref<HTMLElement>) => ReactElement<...>) & { ...; } & { ...; }' does not satisfy the constraint 'keyof IntrinsicElements | JSXElementConstructor<any>'. Type '(<TTag extends ElementType<any> = "button">(props: Props<TTag, TabRenderPropArg, TabPropsWeControl>, ref: Ref<HTMLElement>) => ReactElement<...>) & { ...; } & { ...; }' is not assignable to type '(props: any) => ReactElement<any, any>'.
Exporting the PropTypes would probably still be the nicer solution.