-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flow-strict] Flow strict in Picker.js, PickerIOS.ios.js, PickerAndroid.android.js #22128
Conversation
Generated by 🚫 dangerJS |
type PickerAndroidState = {| | ||
initialSelectedIndex: number, | ||
selectedIndex: number, | ||
items: Array<Item>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically prefer $ReadOnlyArray
over Array
. Hopefully the code in this file isn't modifying this directly so having it be a read only array should be fine with Flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -76,7 +76,7 @@ class PermissionsExample extends React.Component<{}, $FlowFixMeState> { | |||
); | |||
} | |||
|
|||
_onSelectPermission = (permission: string) => { | |||
_onSelectPermission = (permission: string | number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this fix is not needed.
But flow needs... is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure without trying to test it out myself. What flow error do you get without this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this error...
Cannot create Picker element because string [1] is incompatible with number [2] in the
first argument of property onValueChange.
RNTester/js/PermissionsExampleAndroid.android.js
38│ return (
39│ <View style={styles.container}>
40│ <Text style={styles.text}>Permission Name:</Text>
41│ <Picker
42│ style={styles.picker}
43│ selectedValue={this.state.permission}
// this line causes error
44│ onValueChange={this._onSelectPermission.bind(this)}>
45│ <Item
46│ label={PermissionsAndroid.PERMISSIONS.CAMERA}
47│ value={PermissionsAndroid.PERMISSIONS.CAMERA}
48│ />
49│ <Item
50│ label={PermissionsAndroid.PERMISSIONS.READ_CALENDAR}
51│ value={PermissionsAndroid.PERMISSIONS.READ_CALENDAR}
52│ />
53│ <Item
54│ label={PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION}
55│ value={PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION}
56│ />
57│ </Picker>
58│ <TouchableWithoutFeedback onPress={this._checkPermission}>
59│ <View>
60│ <Text style={[styles.touchable, styles.text]}>
:
[1] 79│ _onSelectPermission = (permission: string) => {
@@ -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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this fix is not needed.
But flow needs... is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this error....
Cannot create Picker element because string [1] is incompatible with number [2] in the
first argument of property onValueChange.
RNTester/js/PickerExample.js
37│ return (
38│ <RNTesterPage title="<Picker>">
39│ <RNTesterBlock title="Basic Picker">
40│ <Picker
41│ style={styles.picker}
42│ selectedValue={this.state.selected1}
// this line causes error
43│ onValueChange={this.onValueChange.bind(this, 'selected1')}>
44│ <Item label="hello" value="key0" />
45│ <Item label="world" value="key1" />
46│ </Picker>
47│ </RNTesterBlock>
48│ <RNTesterBlock title="Disabled picker">
49│ <Picker
:
[1] 119│ onValueChange = (key: string, value: string) => {
Libraries/Components/Picker/Picker.js
[2] 73│ onValueChange?: ?(itemValue: string | number, itemIndex: number) => mixed,
Hi @nd-02110114 , is this part of the larger effort under #22100? I plan to combine those entries in the changelog to a single entry, so the changelog section in this PR is n/a. I'll make sure that once this PR lands, you're attributed for your contribution. |
Ah, this makes sense to me. Since an item can have a value of a string or number the function handling the value change must deal with strings or numbers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheSavior is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification. |
@nd-02110114 merged commit 23845fb into |
…(#22128) Summary: Related to #22100 Turn Flow strict mode on for Picker - [x] npm run prettier - [x] npm run flow-check-ios - [x] npm run flow-check-android Pull Request resolved: facebook/react-native#22128 Differential Revision: D12946781 Pulled By: mmmulani fbshipit-source-id: 4d3cb884dd8bf57a43ef8aec4491359e9874d182
Related to #22100
Turn Flow strict mode on for Picker
Test Plan: