Skip to content

Variadic function type signatures are selected by ordering in lib files #2360

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

Closed
justinwoo opened this issue Aug 29, 2016 · 1 comment
Closed

Comments

@justinwoo
Copy link
Contributor

justinwoo commented Aug 29, 2016

I tried asking around and didn't find answers about this behavior other than the flow-typed rxjs typings that describe this defect.

As of 0.31, variadic functions' type signatures aren't selected correctly and the earliest entries will end up being used. This meaning that if I have a typing for the same function for two or three arguments, if the two-arg definition is above the three-arg definition, it will be picked even when using three.

It seems like you can get around this by reversing your definition ordering, but I'm guessing that probably opens a whole 'nother can of worms (if not, it's still not great).

Edit2: Oh, yes, looks like I was really wrong about this, it just matches on the first one The tooltip is wrong, it really does seem to match the correct signature but only if the ordering is reverse from highest number of args going down:

Is this to be expected and solvable in another way, or is this actually a defect?

Repo with more details: https://github.com/justinwoo/flow-type-select-ordering

@vkurchatkin
Copy link
Contributor

It seems like you can get around this by reversing your definition ordering

Yes, that exactly what you need to do. Another trick is to add ...rest: Array<void> as last argument for each signature

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

2 participants