import { type ComponentPropsWithoutRef, type ElementType, type ReactElement, type ReactNode, type Ref, forwardRef, } from 'react' type ElementTagNameMap = HTMLElementTagNameMap & Pick> type AsProp = { as?: Comp ref?: Ref< Comp extends keyof ElementTagNameMap ? ElementTagNameMap[Comp] : Comp extends new (...args: any) => any ? InstanceType : undefined > } & Omit, 'as'> type CompWithAsProp = { displayName?: string; (props: AsProp & Props): ReactElement } export const forwardRefWithAs = ( render: ( props: BaseProps & { as?: ElementType }, ref: React.Ref ) => Exclude ): CompWithAsProp => { // @ts-expect-error return forwardRef(render) }