diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 7300ff6e99..00a0f0a3be 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -560,7 +560,7 @@ declare namespace React { } interface ForwardRefRenderFunction { - (props: PropsWithChildren

, ref: Ref): ReactElement | null; + (props: PropsWithChildren

, ref: ((instance: T | null) => void) | MutableRefObject | null): ReactElement | null; displayName?: string; // explicit rejected with `never` required due to // https://github.com/microsoft/TypeScript/issues/36826 diff --git a/types/react/test/index.ts b/types/react/test/index.ts index b74bb5f98b..0d1c055872 100644 --- a/types/react/test/index.ts +++ b/types/react/test/index.ts @@ -439,6 +439,17 @@ function RefCarryingComponent() { }, ); } +const ForwardingRefComponent2 = React.forwardRef((props, ref) => { + return React.createElement('div', { + ref(e: HTMLDivElement) { + if (typeof ref === 'function') { + ref(e); + } else if (ref) { + ref.current = e; + } + } + }); +}); const MemoizedForwardingRefComponent = React.memo(ForwardingRefComponent); const LazyComponent = React.lazy(() => Promise.resolve({ default: RefComponent }));