Skip to content

Commit

Permalink
Fix Flow types of useEffectEvent (#26468)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
eps1lon authored Mar 25, 2023
1 parent 73b6435 commit d12bdcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ export type Dispatcher = {
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
): void,
useEffectEvent?: <Args, Return, F: (...Array<Args>) => Return>(
callback: F,
) => F,
useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
useInsertionEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
Expand Down
12 changes: 7 additions & 5 deletions packages/react/src/ReactHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,26 @@ export function useSyncExternalStore<T>(

export function useCacheRefresh(): <T>(?() => 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<T>(usable: Usable<T>): 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<any> {
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<T>(callback: T): void {
export function useEffectEvent<Args, F: (...Array<Args>) => 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);
}

0 comments on commit d12bdcd

Please sign in to comment.