Skip to content

Commit

Permalink
backport #3713
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 26, 2022
1 parent 74ad950 commit 0d21c42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,23 @@ 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;
}

interface MutableRefObject<T> {
current: T;
}

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

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

export function forwardRef<R, P = {}>(
fn: ForwardFn<P, R>
): preact.FunctionalComponent<Omit<P, 'ref'> & { ref?: preact.Ref<R> }>;
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 0d21c42

Please sign in to comment.