import React from 'react' export type GenericComponent = keyof JSX.IntrinsicElements | React.ComponentType // Like `Omit`, but not typesafe on `T` so I can exclude keys that may not exist. type Without = Pick> type Props = C extends keyof JSX.IntrinsicElements ? Without, 'as'> : C extends React.ComponentType ? Without : never export type AsProps = { as?: C } & Props type PolyProps = T extends keyof JSX.IntrinsicElements ? P & Omit : T extends React.ComponentType ? P & Omit : never export interface PolyFC { (p: { as?: T } & PolyProps): React.ReactElement | null propTypes?: React.WeakValidationMap

defaultProps?: Partial

displayName?: string } type PolyRefProps = T extends keyof JSX.IntrinsicElements ? P & Omit : T extends React.ComponentType ? P & Omit : never export interface PolyFCWithRef { (p: { as?: T } & PolyRefProps): React.ReactElement | null propTypes?: React.WeakValidationMap

defaultProps?: Partial

displayName?: string } export const polyForwardRef = ( func: ( p: { as?: T } & PolyProps, ref: React.ComponentPropsWithRef['ref'] ) => React.ReactElement | null ): PolyFCWithRef => React.forwardRef(func as any) as any