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

[v2.0] react-select v2 Missing type annotation for U #2716

Closed
erksdee opened this issue Jun 17, 2018 · 8 comments
Closed

[v2.0] react-select v2 Missing type annotation for U #2716

erksdee opened this issue Jun 17, 2018 · 8 comments

Comments

@erksdee
Copy link

erksdee commented Jun 17, 2018

Hi, I'm getting the below error when running flow. Could someone please advise ?

Environment
OS: macOS High Seirra - Version 10.13.4
Node version: v9.6.1
NPM version: 5.7.1

screen shot 2018-06-18 at 9 46 20 am

@gwyneplaine
Copy link
Collaborator

Hi @Erkan1991 which version of flow are you running?

@erksdee
Copy link
Author

erksdee commented Jun 19, 2018

Hi @gwyneplaine, the flow version i'm running is ^0.2.3. However I have manage to get it passing locally with the below updated code block.

File: react-select/src/Select.js
Line number: 1172:14

if (isMulti) {
      const selectValues: Array<any> = selectValue.map(opt => {
      let isFocused = opt === focusedValue;
        return (
          <MultiValue
            {...commonProps}
            components={{
              Container: MultiValueContainer,
              Label: MultiValueLabel,
              Remove: MultiValueRemove,
            }}
            isFocused={isFocused}
            isDisabled={isDisabled}
            key={this.getOptionValue(opt)}
            removeProps={{
              onClick: () => this.removeValue(opt),
              onMouseDown: e => {
                e.preventDefault();
                e.stopPropagation();
              },
            }}
            data={opt}
          >
            {this.formatOptionLabel(opt, 'value')}
          </MultiValue>
        );
      });

      return selectValues;
    }

@SilencerWeb
Copy link

@Erkan1991 but the current flow version is 0.74, try to upgrade flow and run it again

@himerus
Copy link
Contributor

himerus commented Jun 20, 2018

@SilencerWeb

I'm hitting the same issue (was about to create an issue but found this one) and I'm running the latest version of Flow.

$ flow
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/react-select/src/Select.js:1172:14

Missing type annotation for U.

     1169│     }
     1170│
     1171│     if (isMulti) {
     1172│       return selectValue.map(opt => {
     1173│         let isFocused = opt === focusedValue;
     1174│         return (
     1175│           <MultiValue
     1176│             {...commonProps}
     1177│             components={{
     1178│               Container: MultiValueContainer,
     1179│               Label: MultiValueLabel,
     1180│               Remove: MultiValueRemove,
     1181│             }}
     1182│             isFocused={isFocused}
     1183│             isDisabled={isDisabled}
     1184│             key={this.getOptionValue(opt)}
     1185│             removeProps={{
     1186│               onClick: () => this.removeValue(opt),
     1187│               onMouseDown: e => {
     1188│                 e.preventDefault();
     1189│                 e.stopPropagation();
     1190│               },
     1191│             }}
     1192│             data={opt}
     1193│           >
     1194│             {this.formatOptionLabel(opt, 'value')}
     1195│           </MultiValue>
     1196│         );
     1197│       });
     1198│     }
     1199│
     1200│     if (inputValue) {



Found 1 error
error Command failed with exit code 2.

It does appear the above typed solution works properly, and avoids the error in question. I'll fork and submit a PR for this change.

himerus added a commit to himerus/react-select that referenced this issue Jun 21, 2018
gwyneplaine added a commit that referenced this issue Jun 21, 2018
[v2] Fix for #2716 - Missing type annotation for U.
@jossmac jossmac added the v2 label Jul 5, 2018
@DavidBabel
Copy link

@Erkan1991 If you use a return at this point, i guess you are in a function.

The solution is to not let flow infer the return type, and specify it manually :

function yourFunction(array) : Array<any> {
  return array.map( ... );
}

Kind of the same solution you found, but without modifying your code.

@acro5piano
Copy link

acro5piano commented Jul 28, 2018

Hi, I faced the same issue.
In my case, setting the function return type explicitly makes the error gone.

// Error

class Foo {
  id: number

  toParams {
    return {
      id: this.id
    }
  }
}
// No Error

class Foo {
  id: number

  toParams: Object {
    return {
      id: this.id
    }
  }
}

Hope this helps. Thanks

@mike1808
Copy link
Contributor

mike1808 commented Aug 1, 2018

Fixed in #2646

@bladey
Copy link
Contributor

bladey commented May 28, 2020

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.

However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you!

@bladey bladey closed this as completed May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants