From d12bdcda69afd219f4d91cbd60d6fae2a375d35b Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sat, 25 Mar 2023 20:24:00 +0100 Subject: [PATCH] Fix Flow types of useEffectEvent (#26468) ## Summary Just copied the types over from the internal types. Type error was hidden by overly broad FlowFixMe. With `$FlowFixMe[not-a-function]` we would've seen the actual issue: ``` Cannot return `dispatcher.useEffectEvent(...)` because `T` [1] is incompatible with undefined [2].Flow(incompatible-return) ``` ## How did you test this change? - [x] yarn flow dom-node - [x] CI --- packages/react-reconciler/src/ReactInternalTypes.js | 4 +--- packages/react/src/ReactHooks.js | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/react-reconciler/src/ReactInternalTypes.js b/packages/react-reconciler/src/ReactInternalTypes.js index 7f01daa5240da..a672b9669abcf 100644 --- a/packages/react-reconciler/src/ReactInternalTypes.js +++ b/packages/react-reconciler/src/ReactInternalTypes.js @@ -383,9 +383,7 @@ export type Dispatcher = { create: () => (() => void) | void, deps: Array | void | null, ): void, - useEffectEvent?: ) => Return>( - callback: F, - ) => F, + useEffectEvent?: ) => mixed>(callback: F) => F, useInsertionEffect( create: () => (() => void) | void, deps: Array | void | null, diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index 7f1bc8d5e133b..6d157cbc60289 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -218,24 +218,26 @@ export function useSyncExternalStore( export function useCacheRefresh(): (?() => T, ?T) => void { const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + // $FlowFixMe[not-a-function] This is unstable, thus optional return dispatcher.useCacheRefresh(); } export function use(usable: Usable): T { const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + // $FlowFixMe[not-a-function] This is unstable, thus optional return dispatcher.use(usable); } export function useMemoCache(size: number): Array { const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + // $FlowFixMe[not-a-function] This is unstable, thus optional return dispatcher.useMemoCache(size); } -export function useEffectEvent(callback: T): void { +export function useEffectEvent) => mixed>( + callback: F, +): F { const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + // $FlowFixMe[not-a-function] This is unstable, thus optional return dispatcher.useEffectEvent(callback); }