You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to type a create function that returns a fully typed component with ref forwarding and the as prop predefined.
This is needed when using a polymorphic component with CSS-in-JS libraries and other polymorphic components. I'm currently using a createInteractive function in React Interactive, see readme docs, and code.
Building off of your <Heading> example in the readme I have the following, which works but only because I'm using any. Also see this codesandbox which has the below code along with a few other attempts. Thanks!
functioncreateHeadingWithRef<TextendsReact.ElementType=typeofHeadingDefaultElement>(as: T): React.ForwardRefExoticComponent<Omit<HeadingProps<T>,"as">>{// without any get TS error on return type of WrappedHeadingconstWrappedHeading: any=React.forwardRef(function<TextendsReact.ElementType=typeofas>(props: PolymorphicPropsWithoutRef<HeadingOwnProps,T>,ref: React.ForwardedRef<Element>){return<Heading{...props}as={as}ref={ref}/>;});returnWrappedHeading;}
The text was updated successfully, but these errors were encountered:
Hi, I'm trying to type a
create
function that returns a fully typed component with ref forwarding and theas
prop predefined.This is needed when using a polymorphic component with CSS-in-JS libraries and other polymorphic components. I'm currently using a
createInteractive
function in React Interactive, see readme docs, and code.Building off of your
<Heading>
example in the readme I have the following, which works but only because I'm usingany
. Also see this codesandbox which has the below code along with a few other attempts. Thanks!The text was updated successfully, but these errors were encountered: