Skip to content

Commit

Permalink
Fixes to non-product code (e.g React Native)
Browse files Browse the repository at this point in the history
Summary:
We are working on making the empty object literal `{}` have the type `{}` - i.e. exact empty object - rather than being unsealed.

Some manual fixes, in particular to React Native code, which is used and can be synced to other repos (e.g. WWW).

With these changes, error diff in Xplat is down to ~1990 errors

Note that after I roll out `exact_empty_objects`, I'll codemod all the `{...null}` (the only way to get an exact empty object currently) back to `{}`

Changelog: [Internal]

Reviewed By: SamChou19815

Differential Revision: D36142838

fbshipit-source-id: 054caf370db230f42a4c5f5706c88979ef246537
  • Loading branch information
gkz authored and facebook-github-bot committed May 4, 2022
1 parent bf6884d commit 20d9d3a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Libraries/Animated/nodes/AnimatedStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AnimatedStyle extends AnimatedWithChildren {

constructor(style: any) {
super();
style = flattenStyle(style) || {};
style = flattenStyle(style) || ({}: {[string]: any});
if (style.transform) {
style = {
...style,
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ function InternalTextInput(props: Props): React.Node {
// that the update should be ignored and we should stick with the value
// that we have in JS.
useLayoutEffect(() => {
const nativeUpdate = {};
const nativeUpdate: {text?: string, selection?: Selection} = {...null};

if (lastNativeText !== props.value && typeof props.value === 'string') {
nativeUpdate.text = props.value;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Core/setUpPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

if (!global.performance) {
global.performance = {};
global.performance = ({...null}: {now?: () => number});
}

/**
Expand Down
12 changes: 7 additions & 5 deletions Libraries/Image/ImageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ export type ImageSource =
| ImageURISource
| $ReadOnlyArray<ImageURISource>;

export function getImageSourceProperties(
imageSource: ImageURISource,
): $ReadOnly<{
type ImageSourceProperties = {
body?: ?string,
bundle?: ?string,
cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'),
Expand All @@ -104,8 +102,12 @@ export function getImageSourceProperties(
uri?: ?string,
width?: ?number,
...
}> {
const object = {};
};

export function getImageSourceProperties(
imageSource: ImageURISource,
): $ReadOnly<ImageSourceProperties> {
const object: ImageSourceProperties = {};
if (imageSource.body != null) {
object.body = imageSource.body;
}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
_hasDoneInitialScroll = false;
_hasInteracted = false;
_hasMore = false;
_hasWarned = {};
_hasWarned: {[string]: boolean} = {};
_headerLength = 0;
_hiPriInProgress: boolean = false; // flag to prevent infinite hiPri cell limit update
_highestMeasuredFrameIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Utilities/stringifySafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function createStringifySafeWithLimits(limits: {|
retval = `{ ... object with ${keys.length} keys ... }`;
} else if (keys.length > maxObjectKeysLimit) {
// Return a sample of the keys.
retval = {};
retval = ({}: {[string]: mixed});
for (let k of keys.slice(0, maxObjectKeysLimit)) {
retval[k] = value[k];
}
Expand Down
3 changes: 2 additions & 1 deletion Libraries/WebSocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ class WebSocket extends (EventTarget(...WEBSOCKET_EVENTS): any) {
protocols = [protocols];
}

const {headers = {}, ...unrecognized} = options || {};
const {headers = {}, ...unrecognized} = options || {...null};

// Preserve deprecated backwards compatibility for the 'origin' option
// $FlowFixMe[prop-missing]
if (unrecognized && typeof unrecognized.origin === 'string') {
console.warn(
'Specifying `origin` as a WebSocket connection option is deprecated. Include it under `headers` instead.',
Expand Down
6 changes: 5 additions & 1 deletion packages/rn-tester/js/components/RNTesterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ type Props = $ReadOnly<{|
class RNTesterPage extends React.Component<Props> {
render(): React.Node {
let ContentWrapper;
let wrapperProps = {};
let wrapperProps: {
automaticallyAdjustContentInsets?: boolean,
keyboardShouldPersistTaps?: string,
keyboardDismissMode?: string,
} = {...null};
if (this.props.noScroll) {
ContentWrapper = ((View: any): React.ComponentType<any>);
} else {
Expand Down
4 changes: 3 additions & 1 deletion packages/rn-tester/js/examples/Crash/CrashExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ exports.examples = [
<Button
title="JS crash"
onPress={() => {
const a = {};
const a = {...null};
// $FlowIgnore[prop-missing]
// $FlowIgnore[incompatible-use]
const b = a.w.q; // js crash here
console.log(b);
}}
Expand Down

0 comments on commit 20d9d3a

Please sign in to comment.