-
-
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
Flow functions are not type checked by FlowType #1769
Comments
The primary problem is that arrow functions cannot be combined with generators, so
|
for typescript, you can type class MyStore {
@observable
value = ''
print = flow(function*(this: MyStore) {
// type checking worked.
console.log(this.value.toLowerCase())
})
} |
You still loose the return type if you have one. We went with a Babel Transform to convert async methods to flow during transpilation. |
@mweststrate can We use mobx-task here for async actions then. would that suffice? |
Closing for now, will be reopened once #1928 happens. |
It seems to me that functions inside
https://github.com/mobxjs/mobx/blob/master/src/api/flow.ts Am I understanding this wrong? |
FlowType sees
this
inside a flow function as any and so no type checking takes place on this calls.You can get around it by binding the generator function passed to flow.
flow(function*(){yield 1;}.bind(this))
It's easy to forget todo this and I haven't found a lint for it.
Are there any other suggestions on how to get type checking?
Is there a reason why flow isn't a decorator? Is it dangerous in some way if i added it locally?
The text was updated successfully, but these errors were encountered: