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

Improve flow() typing #1825

Merged
merged 1 commit into from
Dec 11, 2018
Merged

Improve flow() typing #1825

merged 1 commit into from
Dec 11, 2018

Conversation

ismailhabib
Copy link
Contributor

See: #1816

@ismailhabib
Copy link
Contributor Author

Impact: before this MR, flow() only need a generic type when the passed function does not have any parameter. Now, it's always required (for a good reason).

@coveralls
Copy link

coveralls commented Dec 2, 2018

Coverage Status

Coverage remained the same at 93.577% when pulling c8dfeab on ismailhabib:master into d55c50a on mobxjs:master.

src/api/flow.ts Outdated
export function flow(generator: Function) {
export function flow<T, U extends any[]>(
generator: (...args: U) => FlowIterator<any>
): CancellablePromise<U> {
Copy link
Contributor

@mayorovp mayorovp Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why <U>? And why CancellablePromise instead of function?

Copy link
Contributor Author

@ismailhabib ismailhabib Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No significant meaning here. It can also be changed to <R, A> to follow the previous naming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it cannot. Right result type is (...args: U) => CancellablePromise<any>

Copy link
Contributor Author

@ismailhabib ismailhabib Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I missed the () => part. Strange that no tests are failing.

edit: nvm, the tests are in .js

@xaviergonz
Copy link
Contributor

There's a way to make flow properly detect the return argument as well (except when the return argument is a promise, but that can be circumvented with a fake function such as castFlowReturn or similar)

See https://github.com/mobxjs/mobx-state-tree/blob/5775437e5267281906ca2ef73a49e7e1bbb410bc/packages/mobx-state-tree/src/core/flow.ts for example

src/api/flow.ts Outdated
export function flow(generator: Function) {
export function flow<T, U extends any[]>(
generator: (...args: U) => FlowIterator<any>
): (...args: U) => CancellablePromise<U> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<U> again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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.

5 participants