-
-
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
Improved flow typing (alternate version) #1827
Conversation
Future: once TS implements Partial type argument inference (microsoft/TypeScript#26349) then "arguments" type could be set to be inferred and then the user would be able to only specify the return type (in this case it would only still be needed for promises) and castFlowReturn could become deprecated. E.g. const act2 = flow<number, _>(function*(x: number, y: string) {
yield Promise.resolve()
return Promise.resolve(2)
}) Still I think the use of castFlowReturn is easier to grasp. |
But how nested promise even possible?.. |
In case the async action wants to return a promise as result, but it should be a really really rare use case. Still supported though |
But this is not supported by runtime!
|
ahh, so when a flow actually returns a promise it waits for it and returns its result! |
fixed and updated the top comment |
Another option of course is just to remove castFlowReturn and force typescript users to yield over it and return the yielded result (now that I know that actually returned promises are awaited first) |
Removed castFlowReturn as the user can just write instead
|
LGTM, Thanks! |
Released in 4.9.0 / 5.9.0 |
gh-pages
branch. Please refer to this PR). For new functionality, at least API.md should be updatednpm run perf
)This PR is kind of like #1825 but with some improvements, since the other PR forces the user give the type of return types AND arguments.
This pr:
Additionally:
Some examples