Skip to content

Commit bcc0567

Browse files
authored
Flow: types first in shared (#25343)
1 parent dc52b67 commit bcc0567

File tree

6 files changed

+29
-31
lines changed

6 files changed

+29
-31
lines changed

packages/react/src/ReactServerContextRegistry.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
110
import type {ReactServerContext} from 'shared/ReactTypes';
211

312
export const ContextRegistry: {

packages/shared/ReactErrorUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function hasCaughtError(): boolean {
109109
return hasError;
110110
}
111111

112-
export function clearCaughtError() {
112+
export function clearCaughtError(): mixed {
113113
if (hasError) {
114114
const error = caughtError;
115115
hasError = false;

packages/shared/ReactServerContextRegistry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
* @flow
88
*/
99

10+
import type {ReactServerContext} from 'shared/ReactTypes';
11+
1012
import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols';
1113
import ReactSharedInternals from 'shared/ReactSharedInternals';
1214
import {createServerContext} from 'react';
1315

1416
const ContextRegistry = ReactSharedInternals.ContextRegistry;
1517

16-
export function getOrCreateServerContext(globalName: string) {
18+
export function getOrCreateServerContext(
19+
globalName: string,
20+
): ReactServerContext<any> {
1721
if (!ContextRegistry[globalName]) {
1822
ContextRegistry[globalName] = createServerContext(
1923
globalName,

packages/shared/enqueueTask.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let didWarnAboutMessageChannel = false;
1111
let enqueueTaskImpl = null;
1212

13-
export default function enqueueTask(task: () => void) {
13+
export default function enqueueTask(task: () => void): void {
1414
if (enqueueTaskImpl === null) {
1515
try {
1616
// read require off the module object to get around the bundlers.

packages/shared/invokeGuardedCallbackImpl.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@
77
* @flow
88
*/
99

10-
function invokeGuardedCallbackProd<A, B, C, D, E, F, Context>(
10+
function invokeGuardedCallbackProd<Args: Array<mixed>, Context>(
1111
name: string | null,
12-
func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
12+
func: (...Args) => mixed,
1313
context: Context,
14-
a: A,
15-
b: B,
16-
c: C,
17-
d: D,
18-
e: E,
19-
f: F,
20-
) {
14+
): void {
2115
const funcArgs = Array.prototype.slice.call(arguments, 3);
2216
try {
17+
// $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
2318
func.apply(context, funcArgs);
2419
} catch (error) {
2520
this.onError(error);
2621
}
2722
}
2823

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;
3029

3130
if (__DEV__) {
3231
// In DEV mode, we swap out invokeGuardedCallback for a special version
@@ -59,24 +58,9 @@ if (__DEV__) {
5958
const fakeNode = document.createElement('react');
6059

6160
invokeGuardedCallbackImpl = function invokeGuardedCallbackDev<
62-
A,
63-
B,
64-
C,
65-
D,
66-
E,
67-
F,
61+
Args: Array<mixed>,
6862
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 {
8064
// If document doesn't exist we know for sure we will crash in this method
8165
// when we call document.createEvent(). However this can cause confusing
8266
// errors: https://github.com/facebook/create-react-app/issues/3482
@@ -142,6 +126,7 @@ if (__DEV__) {
142126
function callCallback() {
143127
didCall = true;
144128
restoreAfterDispatch();
129+
// $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
145130
func.apply(context, funcArgs);
146131
didError = false;
147132
}

scripts/flow/config/flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ well_formed_exports.includes=<PROJECT_ROOT>/packages/react-server-native-relay
8282
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-suspense-test-utils
8383
; well_formed_exports.includes=<PROJECT_ROOT>/packages/react-test-renderer
8484
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
8686
well_formed_exports.includes=<PROJECT_ROOT>/packages/use-subscription
8787
well_formed_exports.includes=<PROJECT_ROOT>/packages/use-sync-external-store
8888

0 commit comments

Comments
 (0)