Skip to content

Commit d12bdcd

Browse files
authored
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
1 parent 73b6435 commit d12bdcd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,7 @@ export type Dispatcher = {
383383
create: () => (() => void) | void,
384384
deps: Array<mixed> | void | null,
385385
): void,
386-
useEffectEvent?: <Args, Return, F: (...Array<Args>) => Return>(
387-
callback: F,
388-
) => F,
386+
useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
389387
useInsertionEffect(
390388
create: () => (() => void) | void,
391389
deps: Array<mixed> | void | null,

packages/react/src/ReactHooks.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,26 @@ export function useSyncExternalStore<T>(
218218

219219
export function useCacheRefresh(): <T>(?() => T, ?T) => void {
220220
const dispatcher = resolveDispatcher();
221-
// $FlowFixMe This is unstable, thus optional
221+
// $FlowFixMe[not-a-function] This is unstable, thus optional
222222
return dispatcher.useCacheRefresh();
223223
}
224224

225225
export function use<T>(usable: Usable<T>): T {
226226
const dispatcher = resolveDispatcher();
227-
// $FlowFixMe This is unstable, thus optional
227+
// $FlowFixMe[not-a-function] This is unstable, thus optional
228228
return dispatcher.use(usable);
229229
}
230230

231231
export function useMemoCache(size: number): Array<any> {
232232
const dispatcher = resolveDispatcher();
233-
// $FlowFixMe This is unstable, thus optional
233+
// $FlowFixMe[not-a-function] This is unstable, thus optional
234234
return dispatcher.useMemoCache(size);
235235
}
236236

237-
export function useEffectEvent<T>(callback: T): void {
237+
export function useEffectEvent<Args, F: (...Array<Args>) => mixed>(
238+
callback: F,
239+
): F {
238240
const dispatcher = resolveDispatcher();
239-
// $FlowFixMe This is unstable, thus optional
241+
// $FlowFixMe[not-a-function] This is unstable, thus optional
240242
return dispatcher.useEffectEvent(callback);
241243
}

0 commit comments

Comments
 (0)