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

feat: support arrow function type shorthand #182

Merged
merged 4 commits into from Feb 12, 2019

Conversation

aaron-harvey
Copy link
Contributor

@aaron-harvey aaron-harvey commented Jan 12, 2017

This PR adds support for arrow expression type shorthand for params and return type. I believe this is a valid way to declare arrow types (flow isn't complaining about it, and flow-ide picks it up).

It also includes a few minor performance enhancements, ie, moving some context things outside of the forEach loop.

// example of what is now supported
type FnType = (a: string, b: number) => number
const arrowFunction: FnType = (a, b) => { return 42; }

Copy link
Collaborator

@danharper danharper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

Instead of checking each param in the type annotation, what do you think about just allowing any arrow whose types come from an annotation on the variable?

e.g. const f: Fn = (a) => a * 2 should pass blindly, instead of checking each param on the arrow? Fn can't be defined without param types anyway, so it's kinda enforced by Flow itself. Also resolves an potential issue where Fn is defined in another file.

@aaron-harvey
Copy link
Contributor Author

@danharper I think this is a good idea - I hadn't considered the case where a type was defined elsewhere.
It also simplifies the code.

@aaron-harvey aaron-harvey force-pushed the feature/extend-function-type-check branch from e0ea145 to 721345a Compare January 18, 2017 17:28
Copy link
Collaborator

@danharper danharper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a valid test for each with a type from another file (e.g. just const f: Foo = (a, b) => 42;)? I haven't tried it, but I don't think that'd pass, because of getTypeAliases which can be removed.

I think it should just be able to check parent.id.typeAnnotation now?

@aaron-harvey
Copy link
Contributor Author

Good catch. I simplified the check and added a test to cover types in another file.

@gajus
Copy link
Owner

gajus commented Jul 9, 2018

Good catch. I simplified the check and added a test to cover types in another file.

Is this still applicable?

@gajus gajus merged commit 58365a0 into gajus:master Feb 12, 2019
@gajus
Copy link
Owner

gajus commented Feb 12, 2019

🎉 This PR is included in version 3.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants