-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 typings for flow() #2164
Conversation
I believe this is duplicate to #2160 :) @xaviergonz what do you think, something useful here? |
This seems to be a fix for flows too, but for "flow" (the facebook thingy) :) That being said I think the declaration could be improved as declare export function flow<R, Args extends any[]>(
generator: (...args: Args) => Generator<any, R, any> | AsyncGenerator<any, R, any>
): (...args: Args) => CancellablePromise<R> Like the TS one for the fix. The one presented here (after the fix) has the same def duplicated twice and casts arguments as Also in TS |
Nevermind about the definition duplication part, I just saw the extra name argument :) The other things might still apply though. |
Wait, actually I don't think flows support a name argument at all, they seem to take the name from the inner generator function |
if you're talking about (?) declare export function flow<T>(
name: string,
fn: (...args: any[]) => T
): (...args: any[]) => Promise<T> then I have removed it because it does not match the signature of how it's implemented. Not sure why it was there. As for the improvements you suggested
I'm not aware of such support. The best I can think of is having this - I'm in favor of adding this if you agree because it's more accurate. declare export function flow<T>(
fn: () => Generator<any, T | Promise<T>, any>
): () => CancellablePromise<T>
declare export function flow<T, A>(
fn: (A) => Generator<any, T | Promise<T>, any>
): (A) => CancellablePromise<T>
declare export function flow<T, A, B>(
fn: (A, B) => Generator<any, T | Promise<T>, any>
): (A, B) => CancellablePromise<T>
// and so on, until let's, say 4 params?
this is required in Flow |
Yep, exactly :)
Shame, that seems like a good workaround (that's how it used to be in TS actually before they added support for that). I'd make it 8-10 args though.
Ahh shame. What about
is that supported? |
why is that a shame? I mean, returning T or Promise are two different things, so Flow makes a distinction there. the PR should be good for merge now |
LGTM, just to make sure, arg names are not required in flow, just the types? |
yes, I tested this locally and it is working fine |
What about MobX4, does it need same tweaks? |
@FredyC this feature works the same there afaik, so no |
@vonovak Wait, so in MobX4 the types were already fixed in the past? Or what do you mean by that? Can you verify it, please? |
sorry, I misunderstood your comment, yes, you should cherry pick this for mobx 4 as well. When do you think this will go public? |
@vonovak Well, I don't really understand what's going on here. Can you cherry-pick, please? :) We certainly won't publish till both branches are in sync. |
This fixes flow typings for flow() which are now fundamentally broken. Flow() returns a cancellable promise (fixed) and a signature that is not valid was removed.
usage:
PR checklist - I think none of these apply for this PR.
/docs
. For new functionality, at leastAPI.md
should be updatednpm run perf
)Feel free to ask help with any of these boxes!
The above process doesn't apply to doc updates etc.