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
Improve flow types #1
Conversation
1. `Generator<...>` is the return type of a generator function, not the generator itself 2. Add an `Args` type parameter, so that it's possible to specify arguments type in a way that works both inside and outside the `gensync` call: ```js var fn = gensync<[number, number], string>(function* (x, y) { return "" }); ```
Ok, I didn't understand the |
Note that this typings don't play well with variadic functions, since a tuple has a fixed length, but except for a few cases are working well for |
} & ( | ||
| { async(...args: Args): Promise<Return> } | ||
// ...args: [...Args, Callback] | ||
| { errback(...args: any[]): void } |
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.
Technically these are both optional too. Does | {}
also work here? I have no idea if Flow can handle that.
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.
At the moment it uses the sync function if neither are provided.
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.
| {}
doesn't work because it isn't an exact object, and if it was we couldn't use &
.
Generator<...>
is the return type of a generator function, not the generator itselfAdd an
Args
type parameter, so that it's possible to specify arguments type in a waythat works both inside and outside the
gensync
call:I had to use
any
because withmixed
I got errors about it not being compatible with the types of the generator function.