From 04684dd9fcaf839cce955d757ccd2d4227f09559 Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:46:36 -0600 Subject: [PATCH] feat: Add `ElementRef` type to compat (#4557) --- compat/src/index.d.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/compat/src/index.d.ts b/compat/src/index.d.ts index 7ceaa09e30..f9aa95ca95 100644 --- a/compat/src/index.d.ts +++ b/compat/src/index.d.ts @@ -286,14 +286,26 @@ declare namespace React { ComponentProps >; - export type ComponentPropsWithRef< - C extends ComponentType | keyof JSXInternal.IntrinsicElements - > = C extends new ( + export type ComponentPropsWithRef = C extends new ( props: infer P ) => Component ? PropsWithoutRef

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