react-polymorphic-box icon indicating copy to clipboard operation
react-polymorphic-box copied to clipboard

Type error with TypeScript 5.2.2

Open GunnarSturla opened this issue 2 years ago • 1 comments

First off, thanks for a fantastic package! Long time happy user, first time bug reporter here :)

Description

Updating TypeScript to 5.2.2 (possibly lower versions as well) causes/reveals a type error in the Box component. My guess would be that TS has changes how it resolves the generics, but to be honest, I don't fully understand how this package works.

Reproduction

Take the example Code Sandbox and update the TypeScript version to 5.2.2 in package.json (it might require reloading the tab)

Here's a link to an updated Sandbox showing the error

Expected behavior

Types should work

Actual behavior

Box component shows the following type error

Type '{ as: "h2"; style: { color: string | undefined; } & LibraryManagedAttributes<E, ComponentPropsWithRef<E>>[string]; } & Omit<...> & { ...; }' is not assignable to type 'IntrinsicAttributes & BoxOwnProps<"h2" & HeadingProps<E>["as"]> & Omit<LibraryManagedAttributes<"h2" & HeadingProps<E>["as"], ComponentPropsWithRef<...>>, "as">'.
  Type '{ as: "h2"; style: { color: string | undefined; } & LibraryManagedAttributes<E, ComponentPropsWithRef<E>>[string]; } & Omit<...> & { ...; }' is not assignable to type 'Omit<LibraryManagedAttributes<"h2" & HeadingProps<E>["as"], ComponentPropsWithRef<"h2" & HeadingProps<E>["as"]>>, "as">'.ts(2322)

Environment

All / Code Sandbox

GunnarSturla avatar Nov 07 '23 10:11 GunnarSturla

Thanks for reporting!

Unfortunately, I’m no longer maintaining this package, but recently wrote an article about how the as prop can be implemented with strong type-safety in place.

Eventually, both this package and react-polymorphic-types should be deprecated in favor of my post above.

kripod avatar Mar 22 '24 07:03 kripod