Problem Statement
Polymorphic as prop should type ref as…
Explanation
A polymorphic component’s ref type depends on the chosen element. Use a generic tied to the as prop so ref stays accurate.
Code Solution
SolutionRead Only
type AsProp<C extends React.ElementType> = { as?: C } & Omit<React.ComponentProps<C>, 'as'>;
// Then forwardRef with a generic C to map the ref correctly.