Skip to content

Commit

Permalink
types: Require initial value in useRef (#4683)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian authored and JoviDeCroock committed Feb 19, 2025
1 parent d9a6c58 commit 49c0171
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
21 changes: 2 additions & 19 deletions compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ import * as preact1 from 'preact';
import { JSXInternal } from '../../src/jsx';
import * as _Suspense from './suspense';

<<<<<<< HEAD
=======
interface SignalLike<T> {
value: T;
peek(): T;
subscribe(fn: (value: T) => void): () => void;
}

type Signalish<T> = T | SignalLike<T>;

declare namespace preact {
export interface FunctionComponent<P = {}> {
(
Expand Down Expand Up @@ -108,7 +98,6 @@ declare namespace preact {
}
}

>>>>>>> Move `defaultProps` into `preact/compat` (#4657)
// export default React;
export = React;
export as namespace React;
Expand All @@ -120,7 +109,6 @@ declare namespace React {
export import CreateHandle = _hooks.CreateHandle;
export import EffectCallback = _hooks.EffectCallback;
export import Inputs = _hooks.Inputs;
export import PropRef = _hooks.PropRef;
export import Reducer = _hooks.Reducer;
export import Dispatch = _hooks.Dispatch;
export import SetStateAction = _hooks.StateUpdater;
Expand Down Expand Up @@ -356,7 +344,7 @@ declare namespace React {
}

export interface ForwardRefRenderFunction<T = any, P = {}> {
(props: P, ref: ForwardedRef<T>): preact.ComponentChild;
(props: P, ref: ForwardedRef<T>): preact1.ComponentChild;
displayName?: string;
}

Expand All @@ -366,13 +354,8 @@ declare namespace React {
}

export function forwardRef<R, P = {}>(
<<<<<<< HEAD
fn: ForwardRefRenderFunction<R, P>
): preact.FunctionalComponent<PropsWithoutRef<P> & { ref?: preact.Ref<R> }>;
=======
fn: ForwardFn<P, R>
fn: ForwardRefRenderFunction<P, R>
): preact1.FunctionalComponent<PropsWithoutRef<P> & { ref?: preact1.Ref<R> }>;
>>>>>>> Move `defaultProps` into `preact/compat` (#4657)

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

Expand Down
13 changes: 3 additions & 10 deletions hooks/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ export function useReducer<S, A, I>(
init: (arg: I) => S
): [S, Dispatch<A>];

/** @deprecated Use the `Ref` type instead. */
type PropRef<T> = MutableRef<T>;

interface MutableRef<T> {
current: T;
}

/**
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
* (`initialValue`). The returned object will persist for the full lifetime of the component.
Expand All @@ -68,9 +61,9 @@ interface MutableRef<T> {
*
* @param initialValue the initial value to store in the ref object
*/
export function useRef<T>(initialValue: T): MutableRef<T>;
export function useRef<T>(initialValue: T | null): RefObject<T>;
export function useRef<T = undefined>(): MutableRef<T | undefined>;
export function useRef<T>(initialValue: T): RefObject<T>;
export function useRef<T>(initialValue: T | null): RefObject<T | null>;
export function useRef<T>(initialValue: T | undefined): RefObject<T | undefined>;

type EffectCallback = () => void | (() => void);
/**
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface VNode<P = {}> {

export type Key = string | number | any;

export type RefObject<T> = { current: T | null };
export type RefObject<T> = { current: T };
export type RefCallback<T> = (instance: T | null) => void;
export type Ref<T> = RefObject<T> | RefCallback<T> | null;
export type Ref<T> = RefCallback<T> | RefObject<T | null> | null;

export type ComponentChild =
| VNode<any>
Expand Down

0 comments on commit 49c0171

Please sign in to comment.