Created
March 21, 2024 16:43
-
-
Save LeandrodeLimaC/6a3025adc168ee282fa5520452a2cade to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TODO: Simplify this type by creating a PolymorphicComponentWithoutRef | |
first and then a PolymorphicComponentWithRef using React.ElementRef<'div'> | |
*/ | |
/** | |
* Props for a polymorphic React component that includes a ref. | |
* | |
* @template E - The expected React element type. | |
* @template P - Additional props specific to the component. | |
*/ | |
export type PolymorphicComponentPropsWithRef< | |
E extends React.ElementType, | |
P = {}, | |
> = DistributiveOmit< | |
React.ComponentPropsWithRef<React.ElementType extends E ? 'div' : E>, | |
'as' & keyof P | |
> & | |
P & | |
AsProp<E> | |
/** | |
* Props for a polymorphic React component without a ref. | |
* | |
* @template E - The expected React element type. | |
* @template P - Additional props specific to the component. | |
*/ | |
export type PolymorphicComponentPropsWithoutRef< | |
E extends React.ElementType, | |
P = {}, | |
> = DistributiveOmit<PolymorphicComponentPropsWithRef<E, P>, 'ref'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment