-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this fix is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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) => { |
||
this.setState({ | ||
permission: permission, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this fix is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
const newState = {}; | ||
newState[key] = value; | ||
this.setState(newState); | ||
|
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
overArray
. 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.
👍