@samitouri / QOS-React-2 / commits / d12bdcda69

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

Sebastian Silbermann committed Mar 25, 2023 at 20:24 UTC d12bdcda69afd219f4d91cbd60d6fae2a375d35b
2 files changed +8 -8
packages/react-reconciler/src/ReactInternalTypes.js
+1 -3
@@ -383,9 +383,7 @@ export type Dispatcher = {
383 create: () => (() => void) | void,
384 deps: Array<mixed> | void | null,
385 ): void,
386 - useEffectEvent?: <Args, Return, F: (...Array<Args>) => Return>(
387 - callback: F,
388 - ) => F,
386 + useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
387 useInsertionEffect(
388 create: () => (() => void) | void,
389 deps: Array<mixed> | void | null,
packages/react/src/ReactHooks.js
+7 -5
@@ -218,24 +218,26 @@ export function useSyncExternalStore<T>(
218
219 export function useCacheRefresh(): <T>(?() => T, ?T) => void {
220 const dispatcher = resolveDispatcher();
221 - // $FlowFixMe This is unstable, thus optional
221 + // $FlowFixMe[not-a-function] This is unstable, thus optional
222 return dispatcher.useCacheRefresh();
223 }
224
225 export function use<T>(usable: Usable<T>): T {
226 const dispatcher = resolveDispatcher();
227 - // $FlowFixMe This is unstable, thus optional
227 + // $FlowFixMe[not-a-function] This is unstable, thus optional
228 return dispatcher.use(usable);
229 }
230
231 export function useMemoCache(size: number): Array<any> {
232 const dispatcher = resolveDispatcher();
233 - // $FlowFixMe This is unstable, thus optional
233 + // $FlowFixMe[not-a-function] This is unstable, thus optional
234 return dispatcher.useMemoCache(size);
235 }
236
237 -export function useEffectEvent<T>(callback: T): void {
237 +export function useEffectEvent<Args, F: (...Array<Args>) => mixed>(
238 + callback: F,
239 +): F {
240 const dispatcher = resolveDispatcher();
239 - // $FlowFixMe This is unstable, thus optional
241 + // $FlowFixMe[not-a-function] This is unstable, thus optional
242 return dispatcher.useEffectEvent(callback);
243 }