kripod / react-polymorphic-types

Zero-runtime polymorphic component definitions for React
MIT License
195 stars 8 forks source link

forwardRef and memo examples don't work with Typescript 5.1 #12

Open Schiavi opened 1 year ago

Schiavi commented 1 year ago

Hello!

I tried to update our typescript to 5.1 and now we are seeing errors on our usage of PolymorphicForwardRefExoticComponent. The same error also happens with PolymorphicMemoExoticComponent

It also errors on playground using the example from the package: TS Playground with Error

Full Error is:

Type 'ForwardRefExoticComponent<Omit<Omit<SVGProps<SVGSymbolElement>, "ref"> | Omit<DetailedHTMLProps<ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>, "ref"> | ... 121 more ... | Omit<...>, "as" | "color"> & HeadingOwnProps & { ...; } & RefAttributes<...>>' is not assignable to type 'PolymorphicForwardRefExoticComponent<HeadingOwnProps, "h2">'.
  Type 'ForwardRefExoticComponent<Omit<Omit<SVGProps<SVGSymbolElement>, "ref"> | Omit<DetailedHTMLProps<ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>, "ref"> | ... 121 more ... | Omit<...>, "as" | "color"> & HeadingOwnProps & { ...; } & RefAttributes<...>>' is not assignable to type '<InstanceT extends ElementType<any> = "h2">(props: PolymorphicPropsWithRef<HeadingOwnProps, InstanceT>) => ReactElement<any, string | JSXElementConstructor<...>> | null'.
    Type 'ReactNode' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'.
      Type 'undefined' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'.

my lib versions are: Typescript: 5.1.3 @types/react: 18.2.14 @types/react-dom: 18.2.6

Thank you