Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align ts definitions from react to refs and forward refs #3713

Merged
Merged
12 changes: 11 additions & 1 deletion compat/src/index.d.ts
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
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