Friday, 12 October 2018

Mobx Flow functions are not type checked by FlowType without .bind(this)

When we use MobX flow decorated functions, flowtype thinks this is of type any and does no type checking.

class MyComponent extends Component<*> {
   actionMethod = flow(function*(){
        yield this.notAMethod();
   });
}

However, if we bind this to the generator, flow understands the type of this is MyComponent.

 class MyComponent extends Component<*> {
       actionMethod = flow((function*(){
            yield this.notAMethod();
       }).bind(this));
    }

My question is how can we ensure that these methods are type checked.

  • Is there any linting rule to ensure we bind(this) correctly?
  • Can we improve the mobx typings?
  • Is this an issue with flow?


from Mobx Flow functions are not type checked by FlowType without .bind(this)

No comments:

Post a Comment