Skip to content

Commit afea1d0

Browse files
authored
[flow] make Flow suppressions explicit on the error (#26487)
Added an explicit type to all $FlowFixMe suppressions to reduce over-suppressions of new errors that might be caused on the same lines. Also removes suppressions that aren't used (e.g. in a `@noflow` file as they're purely misleading) Test Plan: yarn flow-ci
1 parent 768f965 commit afea1d0

File tree

90 files changed

+164
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+164
-209
lines changed

packages/internal-test-utils/internalAct.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function act<T>(scope: () => Thenable<T>): Thenable<T> {
3535
);
3636
}
3737

38-
// $FlowFixMe: Flow doesn't know about global Jest object
38+
// $FlowFixMe[cannot-resolve-name]: Flow doesn't know about global Jest object
3939
if (!jest.isMockFunction(setTimeout)) {
4040
throw Error(
4141
"This version of `act` requires Jest's timer mocks " +
@@ -70,7 +70,7 @@ export async function act<T>(scope: () => Thenable<T>): Thenable<T> {
7070
// Wait until end of current task/microtask.
7171
await waitForMicrotasks();
7272

73-
// $FlowFixMe: Flow doesn't know about global Jest object
73+
// $FlowFixMe[cannot-resolve-name]: Flow doesn't know about global Jest object
7474
if (jest.isEnvironmentTornDown()) {
7575
error.message =
7676
'The Jest environment was torn down before `act` completed. This ' +
@@ -79,7 +79,7 @@ export async function act<T>(scope: () => Thenable<T>): Thenable<T> {
7979
}
8080

8181
if (!Scheduler.unstable_hasPendingWork()) {
82-
// $FlowFixMe: Flow doesn't know about global Jest object
82+
// $FlowFixMe[cannot-resolve-name]: Flow doesn't know about global Jest object
8383
jest.runOnlyPendingTimers();
8484
if (Scheduler.unstable_hasPendingWork()) {
8585
// Committing a fallback scheduled additional work. Continue flushing.

packages/react-client/src/ReactFlightClient.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,20 @@ export function getRoot<T>(response: Response): Thenable<T> {
189189
}
190190

191191
function createPendingChunk<T>(response: Response): PendingChunk<T> {
192-
// $FlowFixMe Flow doesn't support functions as constructors
192+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
193193
return new Chunk(PENDING, null, null, response);
194194
}
195195

196196
function createBlockedChunk<T>(response: Response): BlockedChunk<T> {
197-
// $FlowFixMe Flow doesn't support functions as constructors
197+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
198198
return new Chunk(BLOCKED, null, null, response);
199199
}
200200

201201
function createErrorChunk<T>(
202202
response: Response,
203203
error: ErrorWithDigest,
204204
): ErroredChunk<T> {
205-
// $FlowFixMe Flow doesn't support functions as constructors
205+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
206206
return new Chunk(ERRORED, null, error, response);
207207
}
208208

@@ -253,15 +253,15 @@ function createResolvedModelChunk<T>(
253253
response: Response,
254254
value: UninitializedModel,
255255
): ResolvedModelChunk<T> {
256-
// $FlowFixMe Flow doesn't support functions as constructors
256+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
257257
return new Chunk(RESOLVED_MODEL, value, null, response);
258258
}
259259

260260
function createResolvedModuleChunk<T>(
261261
response: Response,
262262
value: ClientReference<T>,
263263
): ResolvedModuleChunk<T> {
264-
// $FlowFixMe Flow doesn't support functions as constructors
264+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
265265
return new Chunk(RESOLVED_MODULE, value, null, response);
266266
}
267267

packages/react-client/src/ReactFlightReplyClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function processReply(
103103
): ReactJSONValue {
104104
const parent = this;
105105
if (__DEV__) {
106-
// $FlowFixMe
106+
// $FlowFixMe[incompatible-use]
107107
const originalValue = this[key];
108108
if (typeof originalValue === 'object' && originalValue !== value) {
109109
if (objectName(originalValue) !== 'Object') {
@@ -212,7 +212,7 @@ export function processReply(
212212
}
213213
}
214214

215-
// $FlowFixMe
215+
// $FlowFixMe[incompatible-return]
216216
return value;
217217
}
218218

@@ -249,13 +249,13 @@ export function processReply(
249249
}
250250

251251
if (typeof value === 'symbol') {
252-
// $FlowFixMe `description` might be undefined
252+
// $FlowFixMe[incompatible-type] `description` might be undefined
253253
const name: string = value.description;
254254
if (Symbol.for(name) !== value) {
255255
throw new Error(
256256
'Only global symbols received from Symbol.for(...) can be passed to Server Functions. ' +
257257
`The symbol Symbol.for(${
258-
// $FlowFixMe `description` might be undefined
258+
// $FlowFixMe[incompatible-type] `description` might be undefined
259259
value.description
260260
}) cannot be found among global symbols.`,
261261
);

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function useState<S>(
123123
hook !== null
124124
? hook.memoizedState
125125
: typeof initialState === 'function'
126-
? // $FlowFixMe: Flow doesn't like mixed types
126+
? // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
127127
initialState()
128128
: initialState;
129129
hookLog.push({primitive: 'State', stackError: new Error(), value: state});
@@ -674,15 +674,15 @@ function handleRenderFunctionError(error: any): void {
674674
// that the error is caused by user's code in renderFunction.
675675
// In this case, we should wrap the original error inside a custom error
676676
// so that devtools can give a clear message about it.
677-
// $FlowFixMe: Flow doesn't know about 2nd argument of Error constructor
677+
// $FlowFixMe[extra-arg]: Flow doesn't know about 2nd argument of Error constructor
678678
const wrapperError = new Error('Error rendering inspected component', {
679679
cause: error,
680680
});
681681
// Note: This error name needs to stay in sync with react-devtools-shared
682682
// TODO: refactor this if we ever combine the devtools and debug tools packages
683683
wrapperError.name = 'ReactDebugToolsRenderError';
684684
// this stage-4 proposal is not supported by all environments yet.
685-
// $FlowFixMe Flow doesn't have this type yet.
685+
// $FlowFixMe[prop-missing] Flow doesn't have this type yet.
686686
wrapperError.cause = error;
687687
throw wrapperError;
688688
}

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,6 @@ describe('InspectedElement', () => {
18411841
xyz: 1,
18421842
},
18431843
});
1844-
// $FlowFixMe
18451844
const bigInt = BigInt(123); // eslint-disable-line no-undef
18461845

18471846
await utils.actAsync(() =>

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ describe('InspectedElementContext', () => {
873873
xyz: 1,
874874
},
875875
});
876-
// $FlowFixMe
877876
const bigInt = BigInt(123); // eslint-disable-line no-undef
878877

879878
act(() =>

packages/react-devtools-shared/src/__tests__/setupTests.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ beforeEach(() => {
8080
}
8181

8282
const originalConsoleError = console.error;
83-
// $FlowFixMe
8483
console.error = (...args) => {
8584
const firstArg = args[0];
8685
if (
@@ -111,7 +110,6 @@ beforeEach(() => {
111110
originalConsoleError.apply(console, args);
112111
};
113112
const originalConsoleWarn = console.warn;
114-
// $FlowFixMe
115113
console.warn = (...args) => {
116114
if (shouldIgnoreConsoleErrorOrWarn(args)) {
117115
// Allows testing how DevTools behaves when it encounters console.warn without cluttering the test output.

packages/react-devtools-shared/src/__tests__/storeStressTestConcurrent-test.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ describe('StoreStressConcurrent', () => {
6767

6868
// 1. Render a normal version of [a, b, c, d, e].
6969
let container = document.createElement('div');
70-
// $FlowFixMe
7170
let root = ReactDOMClient.createRoot(container);
7271
act(() => root.render(<Parent>{[a, b, c, d, e]}</Parent>));
7372
expect(store).toMatchInlineSnapshot(
@@ -151,7 +150,6 @@ describe('StoreStressConcurrent', () => {
151150
for (let i = 0; i < cases.length; i++) {
152151
// Ensure fresh mount.
153152
container = document.createElement('div');
154-
// $FlowFixMe
155153
root = ReactDOMClient.createRoot(container);
156154

157155
// Verify mounting 'abcde'.
@@ -181,7 +179,6 @@ describe('StoreStressConcurrent', () => {
181179
// 6. Verify *updates* by reusing the container between iterations.
182180
// There'll be no unmounting until the very end.
183181
container = document.createElement('div');
184-
// $FlowFixMe
185182
root = ReactDOMClient.createRoot(container);
186183
for (let i = 0; i < cases.length; i++) {
187184
// Verify mounting 'abcde'.
@@ -249,7 +246,6 @@ describe('StoreStressConcurrent', () => {
249246
const snapshots = [];
250247
let container = document.createElement('div');
251248
for (let i = 0; i < steps.length; i++) {
252-
// $FlowFixMe
253249
const root = ReactDOMClient.createRoot(container);
254250
act(() => root.render(<Root>{steps[i]}</Root>));
255251
// We snapshot each step once so it doesn't regress.
@@ -321,7 +317,6 @@ describe('StoreStressConcurrent', () => {
321317
for (let i = 0; i < steps.length; i++) {
322318
for (let j = 0; j < steps.length; j++) {
323319
container = document.createElement('div');
324-
// $FlowFixMe
325320
const root = ReactDOMClient.createRoot(container);
326321
act(() => root.render(<Root>{steps[i]}</Root>));
327322
expect(print(store)).toMatch(snapshots[i]);
@@ -338,7 +333,6 @@ describe('StoreStressConcurrent', () => {
338333
for (let i = 0; i < steps.length; i++) {
339334
for (let j = 0; j < steps.length; j++) {
340335
container = document.createElement('div');
341-
// $FlowFixMe
342336
const root = ReactDOMClient.createRoot(container);
343337
act(() =>
344338
root.render(
@@ -412,7 +406,6 @@ describe('StoreStressConcurrent', () => {
412406
const snapshots = [];
413407
let container = document.createElement('div');
414408
for (let i = 0; i < steps.length; i++) {
415-
// $FlowFixMe
416409
const root = ReactDOMClient.createRoot(container);
417410
act(() =>
418411
root.render(
@@ -515,7 +508,6 @@ describe('StoreStressConcurrent', () => {
515508

516509
// 2. Verify check Suspense can render same steps as initial fallback content.
517510
for (let i = 0; i < steps.length; i++) {
518-
// $FlowFixMe
519511
const root = ReactDOMClient.createRoot(container);
520512
act(() =>
521513
root.render(
@@ -540,7 +532,6 @@ describe('StoreStressConcurrent', () => {
540532
for (let j = 0; j < steps.length; j++) {
541533
// Always start with a fresh container and steps[i].
542534
container = document.createElement('div');
543-
// $FlowFixMe
544535
const root = ReactDOMClient.createRoot(container);
545536
act(() =>
546537
root.render(
@@ -586,7 +577,6 @@ describe('StoreStressConcurrent', () => {
586577
for (let j = 0; j < steps.length; j++) {
587578
// Always start with a fresh container and steps[i].
588579
container = document.createElement('div');
589-
// $FlowFixMe
590580
const root = ReactDOMClient.createRoot(container);
591581
act(() =>
592582
root.render(
@@ -644,7 +634,6 @@ describe('StoreStressConcurrent', () => {
644634
for (let j = 0; j < steps.length; j++) {
645635
// Always start with a fresh container and steps[i].
646636
container = document.createElement('div');
647-
// $FlowFixMe
648637
const root = ReactDOMClient.createRoot(container);
649638
act(() =>
650639
root.render(
@@ -694,7 +683,6 @@ describe('StoreStressConcurrent', () => {
694683
for (let j = 0; j < steps.length; j++) {
695684
// Always start with a fresh container and steps[i].
696685
container = document.createElement('div');
697-
// $FlowFixMe
698686
const root = ReactDOMClient.createRoot(container);
699687
act(() =>
700688
root.render(
@@ -748,7 +736,6 @@ describe('StoreStressConcurrent', () => {
748736
for (let j = 0; j < steps.length; j++) {
749737
// Always start with a fresh container and steps[i].
750738
container = document.createElement('div');
751-
// $FlowFixMe
752739
const root = ReactDOMClient.createRoot(container);
753740
act(() =>
754741
root.render(
@@ -904,7 +891,6 @@ describe('StoreStressConcurrent', () => {
904891
const snapshots = [];
905892
let container = document.createElement('div');
906893
for (let i = 0; i < steps.length; i++) {
907-
// $FlowFixMe
908894
const root = ReactDOMClient.createRoot(container);
909895
act(() =>
910896
root.render(
@@ -928,7 +914,6 @@ describe('StoreStressConcurrent', () => {
928914
// which is different from the snapshots above. So we take more snapshots.
929915
const fallbackSnapshots = [];
930916
for (let i = 0; i < steps.length; i++) {
931-
// $FlowFixMe
932917
const root = ReactDOMClient.createRoot(container);
933918
act(() =>
934919
root.render(
@@ -1062,7 +1047,6 @@ describe('StoreStressConcurrent', () => {
10621047
for (let j = 0; j < steps.length; j++) {
10631048
// Always start with a fresh container and steps[i].
10641049
container = document.createElement('div');
1065-
// $FlowFixMe
10661050
const root = ReactDOMClient.createRoot(container);
10671051
act(() =>
10681052
root.render(
@@ -1114,7 +1098,6 @@ describe('StoreStressConcurrent', () => {
11141098
for (let j = 0; j < steps.length; j++) {
11151099
// Always start with a fresh container and steps[i].
11161100
container = document.createElement('div');
1117-
// $FlowFixMe
11181101
const root = ReactDOMClient.createRoot(container);
11191102
act(() =>
11201103
root.render(
@@ -1181,7 +1164,6 @@ describe('StoreStressConcurrent', () => {
11811164
for (let j = 0; j < steps.length; j++) {
11821165
// Always start with a fresh container and steps[i].
11831166
container = document.createElement('div');
1184-
// $FlowFixMe
11851167
const root = ReactDOMClient.createRoot(container);
11861168
act(() =>
11871169
root.render(
@@ -1233,7 +1215,6 @@ describe('StoreStressConcurrent', () => {
12331215
for (let j = 0; j < steps.length; j++) {
12341216
// Always start with a fresh container and steps[i].
12351217
container = document.createElement('div');
1236-
// $FlowFixMe
12371218
const root = ReactDOMClient.createRoot(container);
12381219
act(() =>
12391220
root.render(
@@ -1285,7 +1266,6 @@ describe('StoreStressConcurrent', () => {
12851266
for (let j = 0; j < steps.length; j++) {
12861267
// Always start with a fresh container and steps[i].
12871268
container = document.createElement('div');
1288-
// $FlowFixMe
12891269
const root = ReactDOMClient.createRoot(container);
12901270
act(() =>
12911271
root.render(

packages/react-devtools-shared/src/__tests__/utils.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export async function actAsync(
4646
const {act: actTestRenderer} = require('react-test-renderer');
4747
const {act: actDOM} = require('react-dom/test-utils');
4848

49-
// $FlowFixMe Flow doesn't know about "await act()" yet
5049
await actDOM(async () => {
5150
await actTestRenderer(async () => {
5251
await cb();
@@ -55,15 +54,13 @@ export async function actAsync(
5554

5655
if (recursivelyFlush) {
5756
while (jest.getTimerCount() > 0) {
58-
// $FlowFixMe Flow doesn't know about "await act()" yet
5957
await actDOM(async () => {
6058
await actTestRenderer(async () => {
6159
jest.runAllTimers();
6260
});
6361
});
6462
}
6563
} else {
66-
// $FlowFixMe Flow doesn't know about "await act()" yet
6764
await actDOM(async () => {
6865
await actTestRenderer(async () => {
6966
jest.runOnlyPendingTimers();

packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function describeNativeComponentFrame(
7777
let control;
7878

7979
const previousPrepareStackTrace = Error.prepareStackTrace;
80-
// $FlowFixMe It does accept undefined.
80+
// $FlowFixMe[incompatible-type] It does accept undefined.
8181
Error.prepareStackTrace = undefined;
8282

8383
reentry = true;
@@ -98,7 +98,7 @@ export function describeNativeComponentFrame(
9898
const Fake = function () {
9999
throw Error();
100100
};
101-
// $FlowFixMe
101+
// $FlowFixMe[prop-missing]
102102
Object.defineProperty(Fake.prototype, 'props', {
103103
set: function () {
104104
// We use a throwing setter instead of frozen or non-writable props

packages/react-devtools-shared/src/backend/DevToolsConsolePatching.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function disableLogs(): void {
4545
value: disabledLog,
4646
writable: true,
4747
};
48-
// $FlowFixMe Flow thinks console is immutable.
48+
// $FlowFixMe[cannot-write] Flow thinks console is immutable.
4949
Object.defineProperties(console, {
5050
info: props,
5151
log: props,
@@ -69,7 +69,7 @@ export function reenableLogs(): void {
6969
enumerable: true,
7070
writable: true,
7171
};
72-
// $FlowFixMe Flow thinks console is immutable.
72+
// $FlowFixMe[cannot-write] Flow thinks console is immutable.
7373
Object.defineProperties(console, {
7474
log: {...props, value: prevLog},
7575
info: {...props, value: prevInfo},

0 commit comments

Comments
 (0)