Skip to content

Commit

Permalink
feat: Add ElementRef type to compat (#4557)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian authored Dec 1, 2024
1 parent daa124a commit 04684dd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,26 @@ declare namespace React {
ComponentProps<T>
>;

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

export type ElementRef<
C extends
| ForwardRefExoticComponent<any>
| { new (props: any): Component<any, any> }
| ((props: any) => ReactNode)
| keyof JSXInternal.IntrinsicElements
> = 'ref' extends keyof ComponentPropsWithRef<C>
? NonNullable<ComponentPropsWithRef<C>['ref']> extends RefAttributes<
infer Instance
>['ref']
? Instance
: never
: never;

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

Expand Down

0 comments on commit 04684dd

Please # to comment.