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
feat: support arrow function type shorthand #182
Conversation
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.
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.
@danharper I think this is a good idea - I hadn't considered the case where a type was defined elsewhere. |
e0ea145
to
721345a
Compare
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.
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?
Good catch. I simplified the check and added a test to cover types in another file. |
Is this still applicable? |
🎉 This PR is included in version 3.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.