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
This commit is contained in:
Sebastian Silbermann
2023-03-25 20:24:00 +01:00
committed by GitHub
parent 73b6435ca4
commit d12bdcda69
2 changed files with 8 additions and 8 deletions
+1 -3
View File
@@ -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,
+7 -5
View File
@@ -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);
}