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

Flow: types first in shared (#25343)

Jan Kassens committed Oct 3, 2022 at 20:57 UTC bcc05671fcdb159016fb64ab6f0b8f137fa3862c
6 files changed +29 -31
packages/react/src/ReactServerContextRegistry.js
+9
@@ -1,3 +1,12 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 import type {ReactServerContext} from 'shared/ReactTypes';
11
12 export const ContextRegistry: {
packages/shared/ReactErrorUtils.js
+1 -1
@@ -109,7 +109,7 @@ export function hasCaughtError(): boolean {
109 return hasError;
110 }
111
112 -export function clearCaughtError() {
112 +export function clearCaughtError(): mixed {
113 if (hasError) {
114 const error = caughtError;
115 hasError = false;
packages/shared/ReactServerContextRegistry.js
+5 -1
@@ -7,13 +7,17 @@
7 * @flow
8 */
9
10 +import type {ReactServerContext} from 'shared/ReactTypes';
11 +
12 import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols';
13 import ReactSharedInternals from 'shared/ReactSharedInternals';
14 import {createServerContext} from 'react';
15
16 const ContextRegistry = ReactSharedInternals.ContextRegistry;
17
16 -export function getOrCreateServerContext(globalName: string) {
18 +export function getOrCreateServerContext(
19 + globalName: string,
20 +): ReactServerContext<any> {
21 if (!ContextRegistry[globalName]) {
22 ContextRegistry[globalName] = createServerContext(
23 globalName,
packages/shared/enqueueTask.js
+1 -1
@@ -10,7 +10,7 @@
10 let didWarnAboutMessageChannel = false;
11 let enqueueTaskImpl = null;
12
13 -export default function enqueueTask(task: () => void) {
13 +export default function enqueueTask(task: () => void): void {
14 if (enqueueTaskImpl === null) {
15 try {
16 // read require off the module object to get around the bundlers.
packages/shared/invokeGuardedCallbackImpl.js
+12 -27
@@ -7,26 +7,25 @@
7 * @flow
8 */
9
10 -function invokeGuardedCallbackProd<A, B, C, D, E, F, Context>(
10 +function invokeGuardedCallbackProd<Args: Array<mixed>, Context>(
11 name: string | null,
12 - func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
12 + func: (...Args) => mixed,
13 context: Context,
14 - a: A,
15 - b: B,
16 - c: C,
17 - d: D,
18 - e: E,
19 - f: F,
20 -) {
14 +): void {
15 const funcArgs = Array.prototype.slice.call(arguments, 3);
16 try {
17 + // $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
18 func.apply(context, funcArgs);
19 } catch (error) {
20 this.onError(error);
21 }
22 }
23
29 -let invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
24 +let invokeGuardedCallbackImpl: <Args: Array<mixed>, Context>(
25 + name: string | null,
26 + func: (...Args) => mixed,
27 + context: Context,
28 +) => void = invokeGuardedCallbackProd;
29
30 if (__DEV__) {
31 // In DEV mode, we swap out invokeGuardedCallback for a special version
@@ -59,24 +58,9 @@ if (__DEV__) {
58 const fakeNode = document.createElement('react');
59
60 invokeGuardedCallbackImpl = function invokeGuardedCallbackDev<
62 - A,
63 - B,
64 - C,
65 - D,
66 - E,
67 - F,
61 + Args: Array<mixed>,
62 Context,
69 - >(
70 - name: string | null,
71 - func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
72 - context: Context,
73 - a: A,
74 - b: B,
75 - c: C,
76 - d: D,
77 - e: E,
78 - f: F,
79 - ) {
63 + >(name: string | null, func: (...Args) => mixed, context: Context): void {
64 // If document doesn't exist we know for sure we will crash in this method
65 // when we call document.createEvent(). However this can cause confusing
66 // errors: https://github.com/facebook/create-react-app/issues/3482
@@ -142,6 +126,7 @@ if (__DEV__) {
126 function callCallback() {
127 didCall = true;
128 restoreAfterDispatch();
129 + // $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
130 func.apply(context, funcArgs);
131 didError = false;
132 }
scripts/flow/config/flowconfig
+1 -1
@@ -82,7 +82,7 @@ well_formed_exports.includes=<PROJECT_ROOT>/packages/react-server-native-relay
82 well_formed_exports.includes=<PROJECT_ROOT>/packages/react-suspense-test-utils
83 ; well_formed_exports.includes=<PROJECT_ROOT>/packages/react-test-renderer
84 well_formed_exports.includes=<PROJECT_ROOT>/packages/scheduler
85 -; well_formed_exports.includes=<PROJECT_ROOT>/packages/shared
85 +well_formed_exports.includes=<PROJECT_ROOT>/packages/shared
86 well_formed_exports.includes=<PROJECT_ROOT>/packages/use-subscription
87 well_formed_exports.includes=<PROJECT_ROOT>/packages/use-sync-external-store
88