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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare namespace React {
export import Component = preact.Component;
export import FunctionComponent = preact.FunctionComponent;
export import ComponentType = preact.ComponentType;
export import ComponentClass = preact.ComponentClass;
export import FC = preact.FunctionComponent;
export import createContext = preact.createContext;
export import createRef = preact.createRef;
Expand All @@ -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).

export import Consumer = preact.Consumer;

// Suspense
export import Suspense = _Suspense.Suspense;
Expand Down Expand Up @@ -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.

C extends ComponentType<any> | keyof JSXInternal.IntrinsicElements
> = C extends (new(props: infer P) => Component<any, any>)
? PropsWithoutRef<P> & RefAttributes<InstanceType<C>>
: ComponentProps<C>;

export function flushSync<R>(fn: () => R): R;
export function flushSync<A, R>(fn: (a: A) => R, a: A): R;

Expand Down
Loading