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

Bound polymorphism misbehaves with external type annotations #1035

Closed
Gozala opened this issue Nov 4, 2015 · 2 comments
Closed

Bound polymorphism misbehaves with external type annotations #1035

Gozala opened this issue Nov 4, 2015 · 2 comments

Comments

@Gozala
Copy link
Contributor

Gozala commented Nov 4, 2015

Here is an example code thad should but does not produce errors:

/* @flow */

export type Model = {value:number}
export type F <model:Model> = (state:model) => model

export const f:F = (model) => model

f({})

And equivalent with inline type annotations that does error as expected:

/* @flow */

export type Model = {value:number}

export const f = <model:Model> (state:model):model => state

f({})
@samwgoldman
Copy link
Member

The type F is parameterized, but when you used it to annotate the type of f, you didn't supply type parameters. In this case, Flow acts as if you had written F<any>. This is why you don't see an error.

Really, these two code snippets are not equivalent. To be equivalent to the latter snippet, you should define F like so: type F = <model:Model>(state:model) => model.

@Gozala
Copy link
Contributor Author

Gozala commented Nov 4, 2015

@samwgoldman thanks for explanation.

The type F is parameterized, but when you used it to annotate the type of f, you didn't supply type parameters. In this case, Flow acts as if you had written F. This is why you don't see an error.

That behavior seems pretty odd to me because not providing type annotations drops constraint that was defined on the F type which makes me wonder how that is useful ?

In fact I do think that having both type f <x> = () => x and type f = <x> () => x is just going to cause confusion especially if they will have different meanings.

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