Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

nissy-dev
Copy link
Contributor

@nissy-dev nissy-dev commented Nov 5, 2018

Related to #22100

Turn Flow strict mode on for Picker

Test Plan:

  • npm run prettier
  • npm run flow-check-ios
  • npm run flow-check-android

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. ✅pr adds tests labels Nov 5, 2018
@pull-bot
Copy link

pull-bot commented Nov 5, 2018

Warnings
⚠️

📋 Release Notes - This PR may have incorrectly formatted Release Notes.

Generated by 🚫 dangerJS

type PickerAndroidState = {|
initialSelectedIndex: number,
selectedIndex: number,
items: Array<Item>,
Copy link
Member

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.

Copy link
Contributor Author

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) => {
Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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) => {
Copy link
Contributor Author

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?

Copy link
Contributor Author

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,

@turnrye
Copy link
Contributor

turnrye commented Nov 5, 2018

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.

@RSNara RSNara changed the title Flow strict in Picker.js, PickerIOS.ios.js, PickerAndroid.android.js [flow-strict] Flow strict in Picker.js, PickerIOS.ios.js, PickerAndroid.android.js Nov 5, 2018
@elicwhite
Copy link
Member

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.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Nov 6, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@facebook-github-bot facebook-github-bot added Import Failed and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Nov 7, 2018
@facebook-github-bot
Copy link
Contributor

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.

@nissy-dev nissy-dev closed this Nov 27, 2018
facebook-github-bot pushed a commit that referenced this pull request Nov 28, 2018
…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: #22128

Differential Revision: D12946781

Pulled By: mmmulani

fbshipit-source-id: 4d3cb884dd8bf57a43ef8aec4491359e9874d182
@react-native-bot
Copy link
Collaborator

@nd-02110114 merged commit 23845fb into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Nov 28, 2018
@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 28, 2018
rozele pushed a commit to microsoft/react-native-windows that referenced this pull request Jul 18, 2019
…(#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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: PickerIOS Flow Merged This PR has been merged. Platform: Android Android applications. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants