Skip to content

Commit

Permalink
align ts definitions from react to refs and forward refs (#3713)
Browse files Browse the repository at this point in the history
* align ts definitions from react to refs and forward refs

* type ref to also allow null as per react type definition

* add PropsWithChildren also to preact/compat

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
  • Loading branch information
PodaruDragos and JoviDeCroock authored Sep 22, 2022
1 parent 63f285b commit 2cafede
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,29 @@ declare namespace React {
): C;

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

export function forwardRef<R, P = {}>(
fn: ForwardFn<P, R>
): preact.FunctionalComponent<Omit<P, 'ref'> & { ref?: preact.Ref<R> }>;

interface MutableRefObject<T> {
current: T;
}

export type ForwardedRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null;

export function unstable_batchedUpdates(
callback: (arg?: any) => void,
arg?: any
): void;

export type PropsWithChildren<P = unknown> = P & {
children?: preact.ComponentChild | undefined
};

export const Children: {
map<T extends preact.ComponentChild, R>(
children: T | T[],
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type Key = string | number | any;

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

export type ComponentChild =
| VNode<any>
Expand Down

0 comments on commit 2cafede

Please sign in to comment.