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