From 8f0fbd7d6d521ddf7dca96407dded63684fbb9c1 Mon Sep 17 00:00:00 2001 From: nd-02110114 Date: Mon, 5 Nov 2018 13:25:14 +0900 Subject: [PATCH 1/3] flow strict --- Libraries/Components/Picker/Picker.js | 8 ++++---- Libraries/Components/Picker/PickerAndroid.android.js | 4 ++-- Libraries/Components/Picker/PickerIOS.ios.js | 10 +++++----- RNTester/js/PickerExample.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Libraries/Components/Picker/Picker.js b/Libraries/Components/Picker/Picker.js index 88a70a59f6d05f..2f24e50541e526 100644 --- a/Libraries/Components/Picker/Picker.js +++ b/Libraries/Components/Picker/Picker.js @@ -32,7 +32,7 @@ type PickerItemProps = $ReadOnly<{| * The value to be passed to picker's `onValueChange` callback when * this item is selected. Can be a string or an integer. */ - value?: any, + value?: ?(number | string), /** * Color of this item's text. @@ -63,14 +63,14 @@ type PickerProps = $ReadOnly<{| /** * Value matching value of one of the items. Can be a string or an integer. */ - selectedValue?: any, + selectedValue?: ?(number | string), /** * Callback for when an item is selected. This is called with the following parameters: * - `itemValue`: the `value` prop of the item that was selected - * - `itemPosition`: the index of the selected item in this picker + * - `itemIndex`: the index of the selected item in this picker */ - onValueChange?: ?(newValue: any, newIndex: number) => mixed, + onValueChange?: ?(itemValue: number | string, itemIndex: number) => mixed, /** * If set to false, the picker will be disabled, i.e. the user will not be able to make a diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index 2fb010506853e0..f9bced200fb0d1 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -37,7 +37,7 @@ type PickerAndroidProps = $ReadOnly<{| selectedValue?: any, enabled?: ?boolean, mode?: ?('dialog' | 'dropdown'), - onValueChange?: ?(newValue: any, newIndex: number) => mixed, + onValueChange?: ?(itemValue: number | string, itemIndex: number) => mixed, prompt?: ?string, testID?: string, |}>; diff --git a/Libraries/Components/Picker/PickerIOS.ios.js b/Libraries/Components/Picker/PickerIOS.ios.js index fa2fabc09404e2..3087c643cca333 100644 --- a/Libraries/Components/Picker/PickerIOS.ios.js +++ b/Libraries/Components/Picker/PickerIOS.ios.js @@ -27,14 +27,14 @@ import type {TextStyleProp} from 'StyleSheet'; type PickerIOSChangeEvent = SyntheticEvent< $ReadOnly<{| - newValue: any, + newValue: number | string, newIndex: number, |}>, >; type RCTPickerIOSItemType = $ReadOnly<{| label: ?Label, - value: ?any, + value: ?(number | string), textColor: ?number, |}>; @@ -62,8 +62,8 @@ type Props = $ReadOnly<{| children: React.ChildrenArray>, itemStyle?: ?TextStyleProp, onChange?: ?(event: PickerIOSChangeEvent) => mixed, - onValueChange?: ?(newValue: any, newIndex: number) => mixed, - selectedValue: any, + onValueChange?: ?(itemValue: number | string, itemIndex: number) => mixed, + selectedValue: ?(number | string), |}>; type State = {| @@ -73,7 +73,7 @@ type State = {| type ItemProps = $ReadOnly<{| label: ?Label, - value?: ?any, + value?: ?(number | string), color?: ?ColorValue, |}>; diff --git a/RNTester/js/PickerExample.js b/RNTester/js/PickerExample.js index ad234e5ebe8bad..4957916a4a8f26 100644 --- a/RNTester/js/PickerExample.js +++ b/RNTester/js/PickerExample.js @@ -116,7 +116,7 @@ class PickerExample extends React.Component<{}, $FlowFixMeState> { this.setState({mode: newMode}); }; - onValueChange = (key: string, value: string) => { + onValueChange = (key: string, value: string | number) => { const newState = {}; newState[key] = value; this.setState(newState); From 90e4fdf8f838cd9e7913f843c2350009699ff6c4 Mon Sep 17 00:00:00 2001 From: nd-02110114 Date: Mon, 5 Nov 2018 14:11:37 +0900 Subject: [PATCH 2/3] fix error --- Libraries/Components/Picker/Picker.js | 2 +- .../Picker/PickerAndroid.android.js | 22 ++++++++++++++++--- Libraries/Components/Picker/PickerIOS.ios.js | 2 +- .../deepFreezeAndThrowOnMutationInDev-test.js | 2 +- .../js/PermissionsExampleAndroid.android.js | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Libraries/Components/Picker/Picker.js b/Libraries/Components/Picker/Picker.js index 2f24e50541e526..c96f18baf6fbad 100644 --- a/Libraries/Components/Picker/Picker.js +++ b/Libraries/Components/Picker/Picker.js @@ -70,7 +70,7 @@ type PickerProps = $ReadOnly<{| * - `itemValue`: the `value` prop of the item that was selected * - `itemIndex`: the index of the selected item in this picker */ - onValueChange?: ?(itemValue: number | string, itemIndex: number) => mixed, + onValueChange?: ?(itemValue: string | number, itemIndex: number) => mixed, /** * If set to false, the picker will be disabled, i.e. the user will not be able to make a diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index f9bced200fb0d1..bfa29157bf78e2 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -34,18 +34,34 @@ type PickerAndroidChangeEvent = SyntheticEvent< type PickerAndroidProps = $ReadOnly<{| children?: React.Node, style?: ?TextStyleProp, - selectedValue?: any, + selectedValue?: ?(number | string), enabled?: ?boolean, mode?: ?('dialog' | 'dropdown'), - onValueChange?: ?(itemValue: number | string, itemIndex: number) => mixed, + onValueChange?: ?(itemValue: ?(string | number), itemIndex: number) => mixed, prompt?: ?string, testID?: string, |}>; +type Item = $ReadOnly<{| + label: string, + value: ?(number | string), + color?: ?number, +|}>; + +type PickerAndroidState = {| + initialSelectedIndex: number, + selectedIndex: number, + items: Array, +|}; + /** * Not exposed as a public API - use instead. */ -class PickerAndroid extends React.Component { + +class PickerAndroid extends React.Component< + PickerAndroidProps, + PickerAndroidState, +> { /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found * when making Flow check .android.js files. */ constructor(props, context) { diff --git a/Libraries/Components/Picker/PickerIOS.ios.js b/Libraries/Components/Picker/PickerIOS.ios.js index 3087c643cca333..594f913599bff6 100644 --- a/Libraries/Components/Picker/PickerIOS.ios.js +++ b/Libraries/Components/Picker/PickerIOS.ios.js @@ -62,7 +62,7 @@ type Props = $ReadOnly<{| children: React.ChildrenArray>, itemStyle?: ?TextStyleProp, onChange?: ?(event: PickerIOSChangeEvent) => mixed, - onValueChange?: ?(itemValue: number | string, itemIndex: number) => mixed, + onValueChange?: ?(itemValue: string | number, itemIndex: number) => mixed, selectedValue: ?(number | string), |}>; diff --git a/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js b/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js index 1ed6231c663603..f3f8c016026e32 100644 --- a/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js +++ b/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js @@ -134,7 +134,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { expect(o.key1.key2).toBe('newValue'); }); - it('shouldn\'t recurse infinitely', () => { + it("shouldn't recurse infinitely", () => { __DEV__ = true; const o = {}; o.circular = o; diff --git a/RNTester/js/PermissionsExampleAndroid.android.js b/RNTester/js/PermissionsExampleAndroid.android.js index 285b2827f31fdd..e470d755f51b87 100644 --- a/RNTester/js/PermissionsExampleAndroid.android.js +++ b/RNTester/js/PermissionsExampleAndroid.android.js @@ -76,7 +76,7 @@ class PermissionsExample extends React.Component<{}, $FlowFixMeState> { ); } - _onSelectPermission = (permission: string) => { + _onSelectPermission = (permission: string | number) => { this.setState({ permission: permission, }); From f050b4cd9449db1d1491554bfdf5217a5a7284e0 Mon Sep 17 00:00:00 2001 From: nd-02110114 Date: Mon, 5 Nov 2018 16:21:34 +0900 Subject: [PATCH 3/3] fix --- Libraries/Components/Picker/PickerAndroid.android.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index bfa29157bf78e2..2c1ae760e27775 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -51,7 +51,7 @@ type Item = $ReadOnly<{| type PickerAndroidState = {| initialSelectedIndex: number, selectedIndex: number, - items: Array, + items: $ReadOnlyArray, |}; /**