Repository: facebook/react
Pull request: Add flow types to ReactFiberHooks file

Increase type coverage in ReactFiberHooks file.

Changed files:
filename: packages/react-reconciler/src/ReactFiberHooks.js
patch: @@ -268,7 +268,7 @@ let hookTypesUpdateIndexDev: number = -1;
 // When true, such Hooks will always be "remounted". Only used during hot reload.
 let ignorePreviousDependencies: boolean = false;
 
-function mountHookTypesDev() {
+function mountHookTypesDev(): void {
   if (__DEV__) {
     const hookName = ((currentHookNameInDev: any): HookType);
 
@@ -280,7 +280,7 @@ function mountHookTypesDev() {
   }
 }
 
-function updateHookTypesDev() {
+function updateHookTypesDev(): void {
   if (__DEV__) {
     const hookName = ((currentHookNameInDev: any): HookType);
 
@@ -293,7 +293,7 @@ function updateHookTypesDev() {
   }
 }
 
-function checkDepsAreArrayDev(deps: mixed) {
+function checkDepsAreArrayDev(deps: mixed): void {
   if (__DEV__) {
     if (deps !== undefined && deps !== null && !isArray(deps)) {
       // Verify deps, but only on mount to avoid extra checks.
@@ -308,7 +308,7 @@ function checkDepsAreArrayDev(deps: mixed) {
   }
 }
 
-function warnOnHookMismatchInDev(currentHookName: HookType) {
+function warnOnHookMismatchInDev(currentHookName: HookType): void {
   if (__DEV__) {
     const componentName = getComponentNameFromFiber(currentlyRenderingFiber);
     if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
@@ -369,7 +369,7 @@ function throwInvalidHookError() {
 function areHookInputsEqual(
   nextDeps: Array<mixed>,
   prevDeps: Array<mixed> | null,
-) {
+): boolean {
   if (__DEV__) {
     if (ignorePreviousDependencies) {
       // Only true when this component is being hot reloaded.
@@ -681,7 +681,7 @@ function renderWithHooksAgain<Props, SecondArg>(
   Component: (p: Props, arg: SecondArg) => any,
   props: Props,
   secondArg: SecondArg,
-) {
+): any {
   // This is used to perform another render pass. It's used when setState is
   // called during render, and for double invoking components in Strict Mode
   // during development.
@@ -745,7 +745,7 @@ export function bailoutHooks(
   current: Fiber,
   workInProgress: Fiber,
   lanes: Lanes,
-) {
+): void {
   workInProgress.updateQueue = current.updateQueue;
   // TODO: Don't need to reset the flags here, because they're reset in the
   // complete phase (bubbleProperties).
@@ -1732,7 +1732,7 @@ function pushStoreConsistencyCheck<T>(
   fiber: Fiber,
   getSnapshot: () => T,
   renderedSnapshot: T,
-) {
+): void {
   fiber.flags |= StoreConsistency;
   const check: StoreConsistencyCheck<T> = {
     getSnapshot,
@@ -1758,7 +1758,7 @@ function updateStoreInstance<T>(
   inst: StoreInstance<T>,
   nextSnapshot: T,
   getSnapshot: () => T,
-) {
+): void {
   // These are updated in the passive phase
   inst.value = nextSnapshot;
   inst.getSnapshot = getSnapshot;
@@ -1773,7 +1773,11 @@ function updateStoreInstance<T>(
   }
 }
 
-function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
+function subscribeToStore<T>(
+  fiber: Fiber,
+  inst: StoreInstance<T>,
+  subscribe: (() => void) => () => void,
+): any {
   const handleStoreChange = () => {
     // The store changed. Check if the snapshot changed since the last time we
     // read from the store.
@@ -1843,7 +1847,12 @@ function rerenderState<S>(
   return rerenderReducer(basicStateReducer, (initialState: any));
 }
 
-function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
+function pushEffect(
+  tag: HookFlags,
+  create: () => (() => void) | void,
+  destroy: (() => void) | void,
+  deps: Array<mixed> | void | null,
+): Effect {
   const effect: Effect = {
     tag,
     create,
@@ -1963,9 +1972,9 @@ function updateRef<T>(initialValue: T): {current: T} {
 }
 
 function mountEffectImpl(
-  fiberFlags,
-  hookFlags,
-  create,
+  fiberFlags: Flags,
+  hookFlags: HookFlags,
+  create: () => (() => void) | void,
   deps: Array<mixed> | void | null,
 ): void {
   const hook = mountWorkInProgressHook();
@@ -1980,9 +1989,9 @@ function mountEffectImpl(
 }
 
 function updateEffectImpl(
-  fiberFlags,
-  hookFlags,
-  create,
+  fiberFlags: Flags,
+  hookFlags: HookFlags,
+  create: () => (() => void) | void,
   deps: Array<mixed> | void | null,
 ): void {
   const hook = updateWorkInProgressHook();
@@ -2019,14 +2028,14 @@ function mountEffect(
     __DEV__ &&
     (currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
   ) {
-    return mountEffectImpl(
+    mountEffectImpl(
       MountPassiveDevEffect | PassiveEffect | PassiveStaticEffect,
       HookPassive,
       create,
       deps,
     );
   } else {
-    return mountEffectImpl(
+    mountEffectImpl(
       PassiveEffect | PassiveStaticEffect,
       HookPassive,
       create,
@@ -2039,7 +2048,7 @@ function updateEffect(
   create: () => (() => void) | void,
   deps: Array<mixed> | void | null,
 ): void {
-  return updateEffectImpl(PassiveEffect, HookPassive, create, deps);
+  updateEffectImpl(PassiveEffect, HookPassive, create, deps);
 }
 
 function useEventImpl<Args, Return, F: (...Array<Args>) => Return>(
@@ -2099,7 +2108,7 @@ function mountInsertionEffect(
   create: () => (() => void) | void,
   deps: Array<mixed> | void | null,
 ): void {
-  return mountEffectImpl(UpdateEffect, HookInsertion, create, deps);
+  mountEffectImpl(UpdateEffect, HookInsertion, create, deps);
 }
 
 function updateInsertionEffect(
@@ -2133,7 +2142,7 @@ function updateLayoutEffect(
 function imperativeHandleEffect<T>(
   create: () => T,
   ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
-) {
+): void | (() => void) {
   if (typeof ref === 'function') {
     const refCallback = ref;
     const inst = create();
@@ -2186,7 +2195,7 @@ function mountImperativeHandle<T>(
   ) {
     fiberFlags |= MountLayoutDevEffect;
   }
-  return mountEffectImpl(
+  mountEffectImpl(
     fiberFlags,
     HookLayout,
     imperativeHandleEffect.bind(null, create, ref),
@@ -2213,7 +2222,7 @@ function updateImperativeHandle<T>(
   const effectDeps =
     deps !== null && deps !== undefined ? deps.concat([ref]) : null;
 
-  return updateEffectImpl(
+  updateEffectImpl(
     UpdateEffect,
     HookLayout,
     imperativeHandleEffect.bind(null, create, ref),
@@ -2361,7 +2370,11 @@ function updateDeferredValueImpl<T>(hook: Hook, prevValue: T, value: T): T {
   }
 }
 
-function startTransition(setPending, callback, options) {
+function startTransition(
+  setPending: boolean => void,
+  callback: () => void,
+  options?: StartTransitionOptions,
+): void {
   const previousPriority = getCurrentUpdatePriority();
   setCurrentUpdatePriority(
     higherEventPriority(previousPriority, ContinuousEventPriority),
@@ -2483,7 +2496,7 @@ function updateId(): string {
   return id;
 }
 
-function mountRefresh() {
+function mountRefresh(): any {
   const hook = mountWorkInProgressHook();
   const refresh = (hook.memoizedState = refreshCache.bind(
     null,
@@ -2492,12 +2505,12 @@ function mountRefresh() {
   return refresh;
 }
 
-function updateRefresh() {
+function updateRefresh(): any {
   const hook = updateWorkInProgressHook();
   return hook.memoizedState;
 }
 
-function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T) {
+function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T): void {
   if (!enableCache) {
     return;
   }
@@ -2553,7 +2566,7 @@ function dispatchReducerAction<S, A>(
   fiber: Fiber,
   queue: UpdateQueue<S, A>,
   action: A,
-) {
+): void {
   if (__DEV__) {
     if (typeof arguments[3] === 'function') {
       console.error(
@@ -2592,7 +2605,7 @@ function dispatchSetState<S, A>(
   fiber: Fiber,
   queue: UpdateQueue<S, A>,
   action: A,
-) {
+): void {
   if (__DEV__) {
     if (typeof arguments[3] === 'function') {
       console.error(
@@ -2670,7 +2683,7 @@ function dispatchSetState<S, A>(
   markUpdateInDevTools(fiber, lane, action);
 }
 
-function isRenderPhaseUpdate(fiber: Fiber) {
+function isRenderPhaseUpdate(fiber: Fiber): boolean {
   const alternate = fiber.alternate;
   return (
     fiber === currentlyRenderingFiber ||
@@ -2681,7 +2694,7 @@ function isRenderPhaseUpdate(fiber: Fiber) {
 function enqueueRenderPhaseUpdate<S, A>(
   queue: UpdateQueue<S, A>,
   update: Update<S, A>,
-) {
+): void {
   // This is a render phase update. Stash it in a lazily-created map of
   // queue -> linked list of updates. After this render pass, we'll restart
   // and apply the stashed updates on top of the work-in-progress hook.
@@ -2702,7 +2715,7 @@ function entangleTransitionUpdate<S, A>(
   root: FiberRoot,
   queue: UpdateQueue<S, A>,
   lane: Lane,
-) {
+): void {
   if (isTransitionLane(lane)) {
     let queueLanes = queue.lanes;
 
@@ -2723,7 +2736,7 @@ function entangleTransitionUpdate<S, A>(
   }
 }
 
-function markUpdateInDevTools<A>(fiber, lane, action: A) {
+function markUpdateInDevTools<A>(fiber, lane, action: A): void {
   if (__DEV__) {
     if (enableDebugTracing) {
       if (fiber.mode & DebugTracingMode) {