Skip to content

Commit 505588b

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Add annotations or make things readonly to prepare for object literal soundness fix in react-native (#52305)
Summary: Pull Request resolved: #52305 Changelog: [Internal] Reviewed By: marcoww6 Differential Revision: D77386425 fbshipit-source-id: d69184abb1c8f7c516229aafe24dd418b5dd887e
1 parent a6a2884 commit 505588b

13 files changed

Lines changed: 49 additions & 56 deletions

File tree

packages/core-cli-utils/src/private/apple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const tasks = {
125125
}),
126126
),
127127
installDependencies: task(FIFTH, 'Install CocoaPods dependencies', () => {
128-
const env = {
128+
const env: {[string]: string | void} = {
129129
RCT_NEW_ARCH_ENABLED: options.newArchitecture ? '1' : '0',
130130
USE_FRAMEWORKS: options.frameworks,
131131
USE_HERMES: options.hermes ? '1' : '0',

packages/metro-config/src/index.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const INTERNAL_CALLSITES_REGEX = new RegExp(
4343

4444
export {mergeConfig} from 'metro-config';
4545

46-
let frameworkDefaults = {};
46+
let frameworkDefaults: InputConfigT = {};
4747
export function setFrameworkDefaults(config: InputConfigT) {
4848
frameworkDefaults = config;
4949
}

packages/react-native-codegen/src/generators/components/GenerateTests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ TEST(${componentName}_${testName}, etc) {
8181
function getTestCasesForProp(
8282
propName: string,
8383
typeAnnotation: PropTypeAnnotation,
84-
) {
85-
const cases = [];
84+
): Array<TestCase> {
85+
const cases: Array<TestCase> = [];
8686
if (typeAnnotation.type === 'StringEnumTypeAnnotation') {
8787
typeAnnotation.options.forEach(option =>
8888
cases.push({

packages/react-native/Libraries/Animated/AnimatedEvent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import type {NativeSyntheticEvent} from '../Types/CoreEventTypes';
1414
import type {PlatformConfig} from './AnimatedPlatformConfig';
15+
import type {EventMapping} from './NativeAnimatedModule';
1516

1617
import NativeAnimatedHelper from '../../src/private/animated/NativeAnimatedHelper';
1718
import {findNodeHandle} from '../ReactNative/RendererProxy';
@@ -37,7 +38,7 @@ export function attachNativeEventImpl(
3738
): {detach: () => void} {
3839
// Find animated values in `argMapping` and create an array representing their
3940
// key path inside the `nativeEvent` object. Ex.: ['contentOffset', 'x'].
40-
const eventMappings = [];
41+
const eventMappings: Array<EventMapping> = [];
4142

4243
const traverse = (value: mixed, path: Array<string>) => {
4344
if (value instanceof AnimatedValue) {

packages/react-native/Libraries/Animated/__tests__/Animated-test.js

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ describe('Animated', () => {
376376
const anim2 = {start: jest.fn()};
377377
const cb = jest.fn();
378378

379-
// $FlowFixMe[prop-missing]
380-
const seq = Animated.sequence([anim1, anim2]);
379+
const seq = Animated.sequence([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
381380

382381
expect(anim1.start).not.toBeCalled();
383382
expect(anim2.start).not.toBeCalled();
@@ -402,8 +401,7 @@ describe('Animated', () => {
402401
const anim2 = {start: jest.fn()};
403402
const cb = jest.fn();
404403

405-
// $FlowFixMe[prop-missing]
406-
Animated.sequence([anim1, anim2]).start(cb);
404+
Animated.sequence([anim1 as $FlowFixMe, anim2 as $FlowFixMe]).start(cb);
407405

408406
anim1.start.mock.calls[0][0]({finished: false});
409407

@@ -417,8 +415,7 @@ describe('Animated', () => {
417415
const anim2 = {start: jest.fn(), stop: jest.fn()};
418416
const cb = jest.fn();
419417

420-
// $FlowFixMe[prop-missing]
421-
const seq = Animated.sequence([anim1, anim2]);
418+
const seq = Animated.sequence([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
422419
seq.start(cb);
423420
seq.stop();
424421

@@ -436,8 +433,7 @@ describe('Animated', () => {
436433
const anim2 = {start: jest.fn(), stop: jest.fn()};
437434
const cb = jest.fn();
438435

439-
// $FlowFixMe[prop-missing]
440-
const seq = Animated.sequence([anim1, anim2]);
436+
const seq = Animated.sequence([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
441437

442438
seq.start(cb);
443439

@@ -460,8 +456,7 @@ describe('Animated', () => {
460456
const anim2 = {start: jest.fn(), stop: jest.fn()};
461457
const cb = jest.fn();
462458

463-
// $FlowFixMe[prop-missing]
464-
const seq = Animated.sequence([anim1, anim2]);
459+
const seq = Animated.sequence([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
465460

466461
seq.start(cb);
467462
anim1.start.mock.calls[0][0]({finished: true});
@@ -487,8 +482,7 @@ describe('Animated', () => {
487482
};
488483
const cb = jest.fn();
489484

490-
// $FlowFixMe[prop-missing]
491-
const loop = Animated.loop(animation);
485+
const loop = Animated.loop(animation as $FlowFixMe);
492486

493487
expect(animation.start).not.toBeCalled();
494488

@@ -519,8 +513,7 @@ describe('Animated', () => {
519513
};
520514
const cb = jest.fn();
521515

522-
// $FlowFixMe[prop-missing]
523-
const loop = Animated.loop(animation, {iterations: -1});
516+
const loop = Animated.loop(animation as $FlowFixMe, {iterations: -1});
524517

525518
expect(animation.start).not.toBeCalled();
526519

@@ -551,8 +544,10 @@ describe('Animated', () => {
551544
};
552545
const cb = jest.fn();
553546

554-
// $FlowFixMe[prop-missing]
555-
const loop = Animated.loop(animation, {anotherKey: 'value'});
547+
const loop = Animated.loop(
548+
animation as $FlowFixMe,
549+
{anotherKey: 'value'} as $FlowFixMe,
550+
);
556551

557552
expect(animation.start).not.toBeCalled();
558553

@@ -583,8 +578,7 @@ describe('Animated', () => {
583578
};
584579
const cb = jest.fn();
585580

586-
// $FlowFixMe[prop-missing]
587-
const loop = Animated.loop(animation, {iterations: 3});
581+
const loop = Animated.loop(animation as $FlowFixMe, {iterations: 3});
588582

589583
expect(animation.start).not.toBeCalled();
590584

@@ -615,8 +609,7 @@ describe('Animated', () => {
615609
};
616610
const cb = jest.fn();
617611

618-
// $FlowFixMe[prop-missing]
619-
const loop = Animated.loop(animation, {iterations: 1});
612+
const loop = Animated.loop(animation as $FlowFixMe, {iterations: 1});
620613

621614
expect(animation.start).not.toBeCalled();
622615

@@ -637,8 +630,7 @@ describe('Animated', () => {
637630
};
638631
const cb = jest.fn();
639632

640-
// $FlowFixMe[prop-missing]
641-
const loop = Animated.loop(animation, {iterations: 0});
633+
const loop = Animated.loop(animation as $FlowFixMe, {iterations: 0});
642634

643635
expect(animation.start).not.toBeCalled();
644636

@@ -656,8 +648,7 @@ describe('Animated', () => {
656648
};
657649
const cb = jest.fn();
658650

659-
// $FlowFixMe[prop-missing]
660-
Animated.loop(animation).start(cb);
651+
Animated.loop(animation as $FlowFixMe).start(cb);
661652
expect(animation.start).toBeCalled();
662653
expect(animation.reset).toHaveBeenCalledTimes(1);
663654
expect(cb).not.toBeCalled();
@@ -680,8 +671,7 @@ describe('Animated', () => {
680671
};
681672
const cb = jest.fn();
682673

683-
// $FlowFixMe[prop-missing]
684-
const loop = Animated.loop(animation);
674+
const loop = Animated.loop(animation as $FlowFixMe);
685675
loop.start(cb);
686676
loop.stop();
687677

@@ -703,8 +693,10 @@ describe('Animated', () => {
703693
};
704694
const cb = jest.fn();
705695

706-
// $FlowFixMe[prop-missing]
707-
const loop = Animated.loop(animation, {resetBeforeIteration: false});
696+
const loop = Animated.loop(
697+
animation as $FlowFixMe,
698+
{resetBeforeIteration: false} as $FlowFixMe,
699+
);
708700

709701
expect(animation.start).not.toBeCalled();
710702

@@ -730,8 +722,7 @@ describe('Animated', () => {
730722
it('restarts sequence normally in a loop if resetBeforeIteration is false', () => {
731723
const anim1 = {start: jest.fn(), stop: jest.fn()};
732724
const anim2 = {start: jest.fn(), stop: jest.fn()};
733-
// $FlowFixMe[prop-missing]
734-
const seq = Animated.sequence([anim1, anim2]);
725+
const seq = Animated.sequence([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
735726

736727
// $FlowFixMe[prop-missing]
737728
const loop = Animated.loop(seq, {resetBeforeIteration: false});
@@ -761,9 +752,7 @@ describe('Animated', () => {
761752
it('works with an empty element in array', () => {
762753
const anim1 = {start: jest.fn()};
763754
const cb = jest.fn();
764-
// $FlowFixMe[incompatible-call]
765-
// $FlowFixMe[prop-missing]
766-
Animated.parallel([null, anim1]).start(cb);
755+
Animated.parallel([null as $FlowFixMe, anim1 as $FlowFixMe]).start(cb);
767756

768757
expect(anim1.start).toBeCalled();
769758
anim1.start.mock.calls[0][0]({finished: true});
@@ -776,9 +765,7 @@ describe('Animated', () => {
776765
const anim2 = {start: jest.fn()};
777766
const cb = jest.fn();
778767

779-
// $FlowFixMe[prop-missing]
780-
// $FlowFixMe[prop-missing]
781-
const par = Animated.parallel([anim1, anim2]);
768+
const par = Animated.parallel([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
782769

783770
expect(anim1.start).not.toBeCalled();
784771
expect(anim2.start).not.toBeCalled();
@@ -801,8 +788,7 @@ describe('Animated', () => {
801788
const anim2 = {start: jest.fn(), stop: jest.fn()};
802789
const cb = jest.fn();
803790

804-
// $FlowFixMe[prop-missing]
805-
const seq = Animated.parallel([anim1, anim2]);
791+
const seq = Animated.parallel([anim1 as $FlowFixMe, anim2 as $FlowFixMe]);
806792
seq.start(cb);
807793
seq.stop();
808794

@@ -823,8 +809,11 @@ describe('Animated', () => {
823809
const anim3 = {start: jest.fn(), stop: jest.fn()};
824810
const cb = jest.fn();
825811

826-
// $FlowFixMe[prop-missing]
827-
const seq = Animated.parallel([anim1, anim2, anim3]);
812+
const seq = Animated.parallel([
813+
anim1 as $FlowFixMe,
814+
anim2 as $FlowFixMe,
815+
anim3 as $FlowFixMe,
816+
]);
828817
seq.start(cb);
829818

830819
anim1.start.mock.calls[0][0]({finished: false});
@@ -851,8 +840,7 @@ describe('Animated', () => {
851840
it('should call anim after delay in sequence', () => {
852841
const anim = {start: jest.fn(), stop: jest.fn()};
853842
const cb = jest.fn();
854-
// $FlowFixMe[prop-missing]
855-
Animated.sequence([Animated.delay(1000), anim]).start(cb);
843+
Animated.sequence([Animated.delay(1000), anim as $FlowFixMe]).start(cb);
856844
jest.runAllTimers();
857845
expect(anim.start.mock.calls.length).toBe(1);
858846
expect(cb).not.toBeCalled();

packages/react-native/Libraries/Components/Switch/Switch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import type {ColorValue} from '../../StyleSheet/StyleSheet';
1212
import type {NativeSyntheticEvent} from '../../Types/CoreEventTypes';
13+
import type {AccessibilityState} from '../View/ViewAccessibility';
1314
import type {ViewProps} from '../View/ViewPropTypes';
1415

1516
import StyleSheet from '../../StyleSheet/StyleSheet';
@@ -231,7 +232,7 @@ const Switch: component(
231232
const _disabled =
232233
disabled != null ? disabled : accessibilityState?.disabled;
233234

234-
const _accessibilityState =
235+
const _accessibilityState: ?AccessibilityState =
235236
_disabled !== accessibilityState?.disabled
236237
? {...accessibilityState, disabled: _disabled}
237238
: accessibilityState;

packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import type {ColorValue} from '../../StyleSheet/StyleSheet';
12+
import type {AccessibilityState} from '../View/ViewAccessibility';
1213
import type {TouchableWithoutFeedbackProps} from './TouchableWithoutFeedback';
1314

1415
import View from '../../Components/View/View';
@@ -309,7 +310,7 @@ class TouchableHighlightImpl extends React.Component<
309310
const {onBlur, onFocus, ...eventHandlersWithoutBlurAndFocus} =
310311
this.state.pressability.getEventHandlers();
311312

312-
const accessibilityState =
313+
const accessibilityState: ?AccessibilityState =
313314
this.props.disabled != null
314315
? {
315316
...this.props.accessibilityState,

packages/react-native/Libraries/ReactNative/BridgelessUIManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const getUIManagerConstants: ?() => {[viewManagerName: string]: Object} =
3131

3232
const getUIManagerConstantsCached = (function () {
3333
let wasCalledOnce = false;
34-
let result = {};
34+
let result: {[viewManagerName: string]: Object} = {};
3535
return (): {[viewManagerName: string]: Object} => {
3636
if (!wasCalledOnce) {
3737
result = nullthrows(getUIManagerConstants)();

packages/react-native/src/private/animated/createAnimatedPropsMemoHook.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type CompositeKey = {
3131

3232
type CompositeKeyComponent =
3333
| AnimatedNode
34-
| Array<CompositeKeyComponent | null>
35-
| {[string]: CompositeKeyComponent};
34+
| $ReadOnlyArray<CompositeKeyComponent | null>
35+
| $ReadOnly<{[string]: CompositeKeyComponent}>;
3636

3737
type $ReadOnlyCompositeKey = $ReadOnly<{
3838
style?: $ReadOnly<{[string]: CompositeKeyComponent}>,

packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @format
99
*/
1010

11+
import type {ColorValue} from 'react-native';
12+
1113
import RNTesterText from '../../components/RNTesterText';
1214
import React from 'react';
1315
import {
@@ -196,7 +198,7 @@ function PlatformColorsExample() {
196198
}
197199

198200
function FallbackColorsExample() {
199-
let color = {};
201+
let color: {label?: string, color?: ColorValue} = {};
200202
if (Platform.OS === 'ios') {
201203
color = {
202204
label: "PlatformColor('bogus', 'systemGreenColor')",

0 commit comments

Comments
 (0)