Shared Types

NameDefintion
ValidHTMLHeaderLevels
type ValidHTMLHeaderLevels = 1 | 2 | 3 | 4 | 5 | 6;
AsProp
interface AsProp<C extends React.ElementType> {
  as?: C;
}
PropsWithAs
type PropsWithAs<C extends React.ElementType, P> = AsProp<C> & P;
PolymorphicRef
type PolymorphicRef<
  C extends React.ElementType
> = React.ComponentPropsWithRef<C>['ref'];
PolymorphicComponentPropsWithoutRef
type PolymorphicComponentPropsWithoutRef<
  C extends React.ElementType,
  P
> =
  PropsWithAs<C, P> & 
  Omit<
    React.ComponentPropsWithoutRef<C>,
    keyof PropsWithAs<C, P>
  >;
PolymorphicComponentPropsWithRef
type PolymorphicComponentPropsWithRef<
  C extends React.ElementType,
  P
> =
  PropsWithAs<C, P> & 
  Omit<
    React.ComponentPropsWithRef<C>,
    keyof PropsWithAs<C, P>
  >;
PolymorphicForwardRefComponent
interface PolymorphicForwardRefComponent<
  P,
  D extends React.ElementType = React.ElementType
> {
  <C extends React.ElementType = D>(
    props: PolymorphicComponentPropsWithRef<C, P>
  ): React.ReactNode;

  defaultProps?: Partial<PolymorphicComponentPropsWithRef<React.ElementType, P>>;
  propTypes?: React.WeakValidationMap<PolymorphicComponentPropsWithRef<React.ElementType, P>>;
  displayName?: string;
}