From 43cb6af99041a6a16ec37ae4bc0923162d03ce9e Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Tue, 18 Apr 2023 12:16:31 -0700 Subject: [PATCH] Codemod `$Shape` to `Partial` in xplat, suppressing errors [4] (#36960) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36960 We're deprecating the unsafe `$Shape` and moving to the safe `Partial`: https://fb.workplace.com/groups/flowlang/posts/1251655088773485 I have previously codemodded all locations that do not cause errors. Now start on the remaining ones: codemod and suppress. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D45076273 fbshipit-source-id: 951db0f6d850c2c20a87c146370b27a565ae2248 --- .../Libraries/Performance/QuickPerformanceLogger.js | 2 +- .../Libraries/StyleSheet/StyleSheetTypes.js | 12 +++++++----- .../react-native/flow-typed/npm/yargs_v17.x.x.js | 3 +-- .../js/examples/FlatList/BaseFlatListExample.js | 5 ++++- .../examples/SectionList/SectionListBaseExample.js | 3 ++- .../Lists/StateSafePureComponent.js | 2 +- .../Lists/VirtualizedListCellRenderer.js | 2 +- .../Lists/VirtualizedSectionList.js | 2 +- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/react-native/Libraries/Performance/QuickPerformanceLogger.js b/packages/react-native/Libraries/Performance/QuickPerformanceLogger.js index 4a0da73e47825d..57d43e470f8374 100644 --- a/packages/react-native/Libraries/Performance/QuickPerformanceLogger.js +++ b/packages/react-native/Libraries/Performance/QuickPerformanceLogger.js @@ -16,7 +16,7 @@ const DUMMY_INSTANCE_KEY = 0; // Defines map of annotations // Use as following: // {string: {key1: value1, key2: value2}} -export type AnnotationsMap = $Shape<{ +export type AnnotationsMap = Partial<{ string: ?{[string]: string, ...}, int: ?{[string]: number, ...}, double: ?{[string]: number, ...}, diff --git a/packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js b/packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js index 405f9e101659d2..5bb8c8c71b87e7 100644 --- a/packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js +++ b/packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js @@ -892,20 +892,22 @@ type GenericStyleProp<+T> = | $ReadOnlyArray>; export type ____DangerouslyImpreciseStyleProp_Internal = GenericStyleProp< - $Shape<____DangerouslyImpreciseStyle_Internal>, + Partial<____DangerouslyImpreciseStyle_Internal>, >; export type ____ViewStyleProp_Internal = GenericStyleProp< - $ReadOnly<$Shape<____ViewStyle_Internal>>, + $ReadOnly>, >; export type ____TextStyleProp_Internal = GenericStyleProp< - $ReadOnly<$Shape<____TextStyle_Internal>>, + $ReadOnly>, >; export type ____ImageStyleProp_Internal = GenericStyleProp< - $ReadOnly<$Shape<____ImageStyle_Internal>>, + $ReadOnly>, >; export type ____Styles_Internal = { - +[key: string]: $Shape<____DangerouslyImpreciseStyle_Internal>, + // $FlowFixMe[incompatible-exact] + // $FlowFixMe[incompatible-type] + +[key: string]: Partial<____DangerouslyImpreciseStyle_Internal>, ... }; diff --git a/packages/react-native/flow-typed/npm/yargs_v17.x.x.js b/packages/react-native/flow-typed/npm/yargs_v17.x.x.js index 2750236797a305..65f3d61507c803 100644 --- a/packages/react-native/flow-typed/npm/yargs_v17.x.x.js +++ b/packages/react-native/flow-typed/npm/yargs_v17.x.x.js @@ -1,4 +1,3 @@ -// flow-typed signature: cab38813101e0a162deaae556391abc8 // flow-typed version: f7c859e705/yargs_v17.x.x/flow_>=v0.104.x declare module "yargs" { @@ -9,7 +8,7 @@ declare module "yargs" { ... }; - declare type Options = $Shape<{ + declare type Options = Partial<{ alias: string | Array, array: boolean, boolean: boolean, diff --git a/packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js b/packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js index 708f0d9598907d..d4bf8709b614f3 100644 --- a/packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js +++ b/packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js @@ -60,7 +60,7 @@ const Item = ({item, separators}: RenderItemProps) => { }; type Props = { - exampleProps: $Shape>, + exampleProps: Partial>, onTest?: ?() => void, testLabel?: ?string, testOutput?: ?string, @@ -93,11 +93,14 @@ const BaseFlatListExample = React.forwardRef( {props.children} item + index} style={styles.list} + // $FlowFixMe[incompatible-type-arg] renderItem={Item} /> diff --git a/packages/rn-tester/js/examples/SectionList/SectionListBaseExample.js b/packages/rn-tester/js/examples/SectionList/SectionListBaseExample.js index 2bf5c915f95156..f1312dcbb59112 100644 --- a/packages/rn-tester/js/examples/SectionList/SectionListBaseExample.js +++ b/packages/rn-tester/js/examples/SectionList/SectionListBaseExample.js @@ -66,7 +66,7 @@ const Item = ({item, section, separators}) => { }; type Props = { - exampleProps: $Shape>, + exampleProps: Partial>, onTest?: ?() => void, testLabel?: ?string, testOutput?: ?string, @@ -98,6 +98,7 @@ const SectionListBaseExample: React.AbstractComponent< ref={ref} testID="section_list" accessibilityRole="list" + // $FlowFixMe[incompatible-type] sections={DATA} keyExtractor={(item, index) => item + index} style={styles.list} diff --git a/packages/virtualized-lists/Lists/StateSafePureComponent.js b/packages/virtualized-lists/Lists/StateSafePureComponent.js index 909be315c7b565..503f97eba0543b 100644 --- a/packages/virtualized-lists/Lists/StateSafePureComponent.js +++ b/packages/virtualized-lists/Lists/StateSafePureComponent.js @@ -32,7 +32,7 @@ export default class StateSafePureComponent< } setState( - partialState: ?($Shape | ((State, Props) => ?$Shape)), + partialState: ?(Partial | ((State, Props) => ?Partial)), callback?: () => mixed, ): void { if (typeof partialState === 'function') { diff --git a/packages/virtualized-lists/Lists/VirtualizedListCellRenderer.js b/packages/virtualized-lists/Lists/VirtualizedListCellRenderer.js index 91e1a62ad911c9..c4295c0ed93e13 100644 --- a/packages/virtualized-lists/Lists/VirtualizedListCellRenderer.js +++ b/packages/virtualized-lists/Lists/VirtualizedListCellRenderer.js @@ -36,7 +36,7 @@ export type Props = { onUnmount: (cellKey: string) => void, onUpdateSeparators: ( cellKeys: Array, - props: $Shape>, + props: Partial>, ) => void, prevCellKey: ?string, renderItem?: ?RenderItemType, diff --git a/packages/virtualized-lists/Lists/VirtualizedSectionList.js b/packages/virtualized-lists/Lists/VirtualizedSectionList.js index 61519bca4dc866..d217bcde8c5259 100644 --- a/packages/virtualized-lists/Lists/VirtualizedSectionList.js +++ b/packages/virtualized-lists/Lists/VirtualizedSectionList.js @@ -561,7 +561,7 @@ function ItemWithSeparator(props: ItemWithSeparatorProps): React.Node { }, updateProps: ( select: 'leading' | 'trailing', - newProps: $Shape, + newProps: Partial, ) => { if (select === 'leading') { if (LeadingSeparatorComponent != null) {