Skip to content

Commit d1aa1d3

Browse files
rschristianJoviDeCroock
authored andcommitted
types: Require initial value in useRef (#4683)
1 parent d9a6c58 commit d1aa1d3

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

compat/src/index.d.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import * as preact1 from 'preact';
55
import { JSXInternal } from '../../src/jsx';
66
import * as _Suspense from './suspense';
77

8-
<<<<<<< HEAD
9-
=======
10-
interface SignalLike<T> {
11-
value: T;
12-
peek(): T;
13-
subscribe(fn: (value: T) => void): () => void;
14-
}
15-
16-
type Signalish<T> = T | SignalLike<T>;
17-
188
declare namespace preact {
199
export interface FunctionComponent<P = {}> {
2010
(
@@ -108,7 +98,6 @@ declare namespace preact {
10898
}
10999
}
110100

111-
>>>>>>> Move `defaultProps` into `preact/compat` (#4657)
112101
// export default React;
113102
export = React;
114103
export as namespace React;
@@ -120,7 +109,6 @@ declare namespace React {
120109
export import CreateHandle = _hooks.CreateHandle;
121110
export import EffectCallback = _hooks.EffectCallback;
122111
export import Inputs = _hooks.Inputs;
123-
export import PropRef = _hooks.PropRef;
124112
export import Reducer = _hooks.Reducer;
125113
export import Dispatch = _hooks.Dispatch;
126114
export import SetStateAction = _hooks.StateUpdater;
@@ -356,7 +344,7 @@ declare namespace React {
356344
}
357345

358346
export interface ForwardRefRenderFunction<T = any, P = {}> {
359-
(props: P, ref: ForwardedRef<T>): preact.ComponentChild;
347+
(props: P, ref: ForwardedRef<T>): preact1.ComponentChild;
360348
displayName?: string;
361349
}
362350

@@ -366,13 +354,8 @@ declare namespace React {
366354
}
367355

368356
export function forwardRef<R, P = {}>(
369-
<<<<<<< HEAD
370357
fn: ForwardRefRenderFunction<R, P>
371-
): preact.FunctionalComponent<PropsWithoutRef<P> & { ref?: preact.Ref<R> }>;
372-
=======
373-
fn: ForwardFn<P, R>
374358
): preact1.FunctionalComponent<PropsWithoutRef<P> & { ref?: preact1.Ref<R> }>;
375-
>>>>>>> Move `defaultProps` into `preact/compat` (#4657)
376359

377360
export type PropsWithoutRef<P> = Omit<P, 'ref'>;
378361

hooks/src/index.d.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ export function useReducer<S, A, I>(
5252
init: (arg: I) => S
5353
): [S, Dispatch<A>];
5454

55-
/** @deprecated Use the `Ref` type instead. */
56-
type PropRef<T> = MutableRef<T>;
57-
58-
interface MutableRef<T> {
59-
current: T;
60-
}
61-
6255
/**
6356
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
6457
* (`initialValue`). The returned object will persist for the full lifetime of the component.
@@ -68,9 +61,9 @@ interface MutableRef<T> {
6861
*
6962
* @param initialValue the initial value to store in the ref object
7063
*/
71-
export function useRef<T>(initialValue: T): MutableRef<T>;
72-
export function useRef<T>(initialValue: T | null): RefObject<T>;
73-
export function useRef<T = undefined>(): MutableRef<T | undefined>;
64+
export function useRef<T>(initialValue: T): RefObject<T>;
65+
export function useRef<T>(initialValue: T | null): RefObject<T | null>;
66+
export function useRef<T>(initialValue: T | undefined): RefObject<T | undefined>;
7467

7568
type EffectCallback = () => void | (() => void);
7669
/**

src/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export interface VNode<P = {}> {
3737

3838
export type Key = string | number | any;
3939

40-
export type RefObject<T> = { current: T | null };
40+
export type RefObject<T> = { current: T };
4141
export type RefCallback<T> = (instance: T | null) => void;
42-
export type Ref<T> = RefObject<T> | RefCallback<T> | null;
42+
export type Ref<T> = RefCallback<T> | RefObject<T | null> | null;
4343

4444
export type ComponentChild =
4545
| VNode<any>

0 commit comments

Comments
 (0)