kripod / kripod/react-polymorphic-box

Type error with TypeScript 5.2.2

Open
#26 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
346
Forks
14
PR merge metrics
No merged PRs in 30d

Description

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](https://codesandbox.io/s/react-polymorphic-box-forwarding-refs-forked-yfg4vj?file=/src/App.tsx)

## Expected behavior

Types should work

## Actual behavior

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

## Environment

All / Code Sandbox

Contributor guide

Open the contributing guide

Research direction

Reproduce the error in the linked CodeSandbox by updating package.json to TypeScript 5.2.2. Start at the Box component's polymorphic generic typing and check how its props are resolved with that TypeScript version. Done means the example type-checks without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.