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

Flow cannot see typings inside extendObservable #1346

Closed
houshuang opened this issue Feb 7, 2018 · 2 comments
Closed

Flow cannot see typings inside extendObservable #1346

houshuang opened this issue Feb 7, 2018 · 2 comments

Comments

@houshuang
Copy link

Because of problems getting decorators to work with Babel 7 (#1345), I tried switching to extendObservable, which worked perfectly, however now Flow doesn't recognize any of my typings, so ie if I have

class A {
  constructor() {
    extendObservable(this, {
      setName: action((name: string) => { ... }
    })
  }
}

const a = new A()
a.setName('hello')

This will work fine, however Flow will complain that a doesn't have a method setName. I could add all of the type definitions in the top of the class file, but we're talking many tens of actions and computed properties across a bunch of files. IS there any way to get Flow to pick up the typings from extendObservable? (With decorators, this worked flawlessly).

thanks!

@mweststrate
Copy link
Member

mweststrate commented Feb 7, 2018 via email

@mweststrate
Copy link
Member

Edit: sorry, misread the question initially. Probably you should still declare setName in your class:

class A {
  constructor() {
    extendObservable(this, {
      setName: action((name: string) => { ... }
    })
  }

  setName: (name:string) => void;
}

Not entirely sure how that is done properly in flow :). But, from Mobx4 onward, you can simply do this:

import { decorate, action } from "mobx"

class A {
  setName(name: string) {
  }
}
decorate(A, { setName: action })

Which should avoid the typing problem

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

No branches or pull requests

2 participants