import type React from 'react'; type ExtendedProps = OverrideProps & Omit; type ElementType = keyof JSX.IntrinsicElements | React.JSXElementConstructor; type PropsOf = JSX.LibraryManagedAttributes>; type ComponentProp = { component?: C; }; type InheritedProps = ExtendedProps, Props>; export type PolymorphicRef = C extends React.ElementType ? React.ComponentPropsWithRef['ref'] : never; export type PolymorphicComponentProps = C extends React.ElementType ? InheritedProps> & { ref?: PolymorphicRef; renderRoot?: (props: any) => any; } : Props & { component: React.ElementType; renderRoot?: (props: Record) => any }; export function createPolymorphicComponent>( component: any ) { type ComponentProps = PolymorphicComponentProps; type _PolymorphicComponent = (props: ComponentProps) => React.ReactElement; type ComponentProperties = Omit>, never>; type PolymorphicComponent = _PolymorphicComponent & ComponentProperties & StaticComponents; return component as PolymorphicComponent; }