3 ComponentPropsWithoutRef,
6 ForwardRefExoticComponent,
13 type Merge<T, U> = Omit<T, keyof U> & U;
15 type PropsWithAs<P, T extends ElementType> = P & { as?: T };
16 type UnknownProps<P> = P & { [key: string]: unknown };
18 type ExtractPropsWithRef<T> = T extends keyof JSX.IntrinsicElements
19 ? PropsWithRef<JSX.IntrinsicElements[T]>
20 : ComponentPropsWithRef<T>;
22 type ExtractPropsWithoutRef<T> = T extends keyof JSX.IntrinsicElements
23 ? PropsWithoutRef<JSX.IntrinsicElements[T]>
24 : ComponentPropsWithoutRef<T>;
26 type PolymorphicRefForwardingFunction<P, T extends ElementType> = <InstanceT extends ElementType = T>(
27 props: PolymorphicPropsWithRef<P, InstanceT>
30 type PolymorphicExoticComponent<P = {}, T extends ElementType> = Merge<
31 ExoticComponent<UnknownProps<P>>,
32 PolymorphicRefForwardingFunction<P, T>
35 export type PolymorphicPropsWithoutRef<P, T extends ElementType> = Merge<ExtractPropsWithoutRef<T>, PropsWithAs<P, T>>;
36 export type PolymorphicPropsWithRef<P, T extends ElementType> = Merge<ExtractPropsWithRef<T>, PropsWithAs<P, T>>;
38 export type PolymorphicForwardRefExoticComponent<P, T extends ElementType> = Merge<
39 ForwardRefExoticComponent<UnknownProps<P>>,
40 PolymorphicExoticComponent<P, T>