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

ts: improve preact compat types adding a few missing @types/react used by styled-components #4271

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

jduthon
Copy link
Contributor

@jduthon jduthon commented Feb 2, 2024

Hello preact team!

Recently, we ran into some TypeScript issues in a project where we use preact with styled-components.

Looking a bit more in depth at the issues, they seemed to stem from a few missing types from @types/react, this PR aims to add those types in.

With those changes, we got a project with preact+styled-components working correctly (PS: this is a good first sign, but the project isn't that huge, so there could be things that don't work in 100% of the situations)

It would likely fix this issue

@@ -55,6 +56,8 @@ declare namespace React {
export import cloneElement = preact.cloneElement;
export import ComponentProps = preact.ComponentProps;
export import ReactNode = preact.ComponentChild;
export import ReactElement = preact.VNode;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

VNode seemed to be the closest thing in preact to ReactElement from what I could gather, but this might be wrong.

Copy link
Member

Choose a reason for hiding this comment

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

Seems right, VNode looks to cover all the same properties (and a couple more).

@@ -169,6 +172,12 @@ declare namespace React {
| MutableRefObject<T | null>
| null;

export type ComponentPropsWithRef<
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I mixed the @types/react implementation with preact's one for ComponentProps.
I think this makes sense, but I have some doubts, so would be great if someone with more understanding of the preact side can confirm 👼

Choose a reason for hiding this comment

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

this cause issue #4293.

@jduthon jduthon marked this pull request as ready for review February 2, 2024 11:18
@coveralls
Copy link

Coverage Status

coverage: 99.473%. remained the same
when pulling 3c15598 on jduthon:fix/react-types-compat
into 49433b3 on preactjs:main.

@JoviDeCroock JoviDeCroock merged commit a3f7c33 into preactjs:main Feb 2, 2024
2 checks passed
@JoviDeCroock JoviDeCroock mentioned this pull request Feb 3, 2024
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.

5 participants