Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ElementRef type to compat #4557

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Nov 15, 2024

Closes #4481

For comparison: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b5dc32740d9b45d11cff9b025896dd333c795b39/types/react/index.d.ts#L221-L235

Can confirm #4548 cleared the way for this -- like a total doofus I created a new vite project and was wildy confused to see the same old error re: can't assign null | undefined to VNode<any> as I had only copied over this particular change. Eventually the issue dawned on me, copied over the new types, and it worked like a treat!

export type ComponentPropsWithRef<
C extends ComponentType<any> | keyof JSXInternal.IntrinsicElements
> = C extends new (
export type ComponentPropsWithRef<C extends ElementType> = C extends new (
Copy link
Member Author

@rschristian rschristian Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't originally have ElementType when I added ComponentPropsWithRef but someone kiindly added it a few months ago. It's worth switching this over, helps ensure things are kept in-sync.

For comparison: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b5dc32740d9b45d11cff9b025896dd333c795b39/types/react/index.d.ts#L1687-L1689

@coveralls
Copy link

Coverage Status

coverage: 99.486%. remained the same
when pulling e06a37e on types/element-ref
into 68ada1a on main.

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this behave in 5.0?

@rschristian
Copy link
Member Author

That's a great question. Will investigate further

@rschristian
Copy link
Member Author

Ignoring our resolution issues for the moment, this seems to work as we need? It does produce a type error in the compat declaration file, but in 5.0 & 5.1, the user is presented with a seemingly functional & identical type. This would require skipLibCheck, but most of our users are probably doing so anyhow (our Vite templates all do this by default).

Copy/pasting the shadcn examples given in the issue, there doesn't seem to be a user-facing problem, it's just that the generic doesn't satisfy. I'm not well enough informed to say whether this is a problem or not though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Module "preact/compat" has no exported member ElementRef
3 participants