diff --git a/compat/src/index.d.ts b/compat/src/index.d.ts index 810629c199..a71a21564c 100644 --- a/compat/src/index.d.ts +++ b/compat/src/index.d.ts @@ -18,7 +18,6 @@ declare namespace React { export import PropRef = _hooks.PropRef; export import Reducer = _hooks.Reducer; export import Dispatch = _hooks.Dispatch; - export import Ref = _hooks.Ref; export import SetStateAction = _hooks.StateUpdater; export import useCallback = _hooks.useCallback; export import useContext = _hooks.useContext; @@ -50,6 +49,7 @@ declare namespace React { export import ComponentClass = preact.ComponentClass; export import FC = preact.FunctionComponent; export import createContext = preact.createContext; + export import Ref = preact.Ref; export import createRef = preact.createRef; export import Fragment = preact.Fragment; export import createElement = preact.createElement; diff --git a/compat/test/ts/forward-ref.tsx b/compat/test/ts/forward-ref.tsx index 9a920cb05c..25d0694079 100644 --- a/compat/test/ts/forward-ref.tsx +++ b/compat/test/ts/forward-ref.tsx @@ -24,3 +24,7 @@ export const Bar = React.forwardRef( return
{props.children}
; } ); + +export const baz = ( + ref: React.ForwardedRef +): React.Ref => ref; diff --git a/hooks/src/index.d.ts b/hooks/src/index.d.ts index 3ec8999ca6..7bb441edb2 100644 --- a/hooks/src/index.d.ts +++ b/hooks/src/index.d.ts @@ -1,4 +1,4 @@ -import { ErrorInfo, PreactContext, Ref as PreactRef } from '../..'; +import { ErrorInfo, PreactContext, Ref, RefObject } from '../..'; type Inputs = ReadonlyArray; @@ -52,9 +52,6 @@ export function useReducer( /** @deprecated Use the `Ref` type instead. */ type PropRef = MutableRef; -interface Ref { - readonly current: T | null; -} interface MutableRef { current: T; @@ -70,7 +67,7 @@ interface MutableRef { * @param initialValue the initial value to store in the ref object */ export function useRef(initialValue: T): MutableRef; -export function useRef(initialValue: T | null): Ref; +export function useRef(initialValue: T | null): RefObject; export function useRef(): MutableRef; type EffectCallback = () => void | (() => void); @@ -92,7 +89,7 @@ type CreateHandle = () => object; * @param inputs If present, effect will only activate if the values in the list change (using ===). */ export function useImperativeHandle( - ref: PreactRef, + ref: Ref, create: () => R, inputs?: Inputs ): void;