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

Fix Flow type ambiguity #1164

Merged
merged 1 commit into from
Jan 5, 2017
Merged

Conversation

leebyron
Copy link
Contributor

@leebyron leebyron commented Dec 23, 2016

Fixes #1114

As reported in #1114, flow reports ambiguity when defining tests:

test('my test', t => {})

Flow will report that it could apply either the Test type or the Macro type. The Test type is an obvious fit, but Macro also applies since the ...args resolves to the empty array, and the optional title? attribute happens to be not provided.

My suggested fix is to merge the Test and Macro types together since Macro is really a superset of the Test type, and we don't lose any type safety by just expecting to always get Macros.

I tested this locally on a flow-typed repository and confirmed that the type ambiguity errors are solved.

@bookercodes
Copy link
Contributor

Thanks for this, @leebyron!

Can't wait for this to be merged 🎆. In the meantime, is there a convinent way to apply this patch, do you know?

@bookercodes
Copy link
Contributor

Hm. I tried to apply this locally but ran into some trouble. If anyone has any ideas, please let me know! Thanks!

@novemberborn
Copy link
Member

My suggested fix is to merge the Test and Macro types together since Macro is really a superset of the Test type, and we don't lose any type safety by just expecting to always get Macros.

I haven't looked at (these, or any, really) Flow definitions much. From the test() method's perspective the t => {} function is a test implementation. "Macro" is more a way of explaining how to reuse test implementations, AVA doesn't care. Perhaps the types can be renamed Implementation rather than TestOrMacro?

Besides that, if Flow-users could try out this PR that'd be great. I don't really know how to test it myself.

Fixes avajs#1114

As reported in avajs#1114, flow reports ambiguity when defining tests:

```js
test('my test', t => {})
```

Flow will report that it could apply either the `Test` type or the `Macro` type. The `Test` type is an obvious fit, but `Macro` also applies since the `...args` resolves to the empty array, and the `title?` attribute happens to be not provided.

My suggested fix is to merge the `Test` and `Macro` types together since `Macro` is really a superset of the `Test` type, and we don't lose any type safety by just expecting to always get Macros. This super set type is called `TestImplementation` which better matches how AVA names these things.

I tested this locally on a flow-typed repository and confirmed that the type ambiguity errors are solved.
@leebyron
Copy link
Contributor Author

Great suggestion - I cleaned up the names of the types.

Anyone who would like to test this out locally, here's how I'm doing it:

@bookercodes
Copy link
Contributor

@leebyron Ah, I guess you could say npm link was the missing... link. Gosh, I'm hilarious!

Jokes aside, I managed to apply your fix locally and things work smoothly in my project, thanks!

@sindresorhus sindresorhus changed the title Fix: Flow type ambiguity Fix Flow type ambiguity Jan 5, 2017
@sindresorhus sindresorhus merged commit 314f7a0 into avajs:master Jan 5, 2017
@sindresorhus
Copy link
Member

Thanks for helping us out with this one @leebyron. We really appreciate it. No one on the team has much experience with Flow.

@leebyron
Copy link
Contributor Author

leebyron commented Jan 6, 2017

Thanks for the merge. Feel free to shout my way if you ever need help with anything related to type definitions.

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

Successfully merging this pull request may close these issues.

ava 0.17.0 with FlowType 0.35.0 results in type-ambiguity errors
4 participants