From 2cafedee2ddf7c73795e887ef1970df4be2bca90 Mon Sep 17 00:00:00 2001 From: Podaru Dragos Date: Fri, 23 Sep 2022 00:15:37 +0300 Subject: [PATCH] align ts definitions from react to refs and forward refs (#3713) * 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 --- compat/src/index.d.ts | 12 +++++++++++- src/index.d.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compat/src/index.d.ts b/compat/src/index.d.ts index eaf108fee1..ebff341dfd 100644 --- a/compat/src/index.d.ts +++ b/compat/src/index.d.ts @@ -124,7 +124,7 @@ declare namespace React { ): C; export interface ForwardFn

{ - (props: P, ref: Ref): preact.ComponentChild; + (props: P, ref: ForwardedRef): preact.ComponentChild; displayName?: string; } @@ -132,11 +132,21 @@ declare namespace React { fn: ForwardFn ): preact.FunctionalComponent & { ref?: preact.Ref }>; + interface MutableRefObject { + current: T; + } + + export type ForwardedRef = ((instance: T | null) => void) | MutableRefObject | null; + export function unstable_batchedUpdates( callback: (arg?: any) => void, arg?: any ): void; + export type PropsWithChildren

= P & { + children?: preact.ComponentChild | undefined + }; + export const Children: { map( children: T | T[], diff --git a/src/index.d.ts b/src/index.d.ts index 44b5acb71c..06fe433fa5 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -39,7 +39,7 @@ export type Key = string | number | any; export type RefObject = { current: T | null }; export type RefCallback = (instance: T | null) => void; -export type Ref = RefObject | RefCallback; +export type Ref = RefObject | RefCallback | null; export type ComponentChild = | VNode