Search code examples
visual-studio-codejsdocmobx-state-tree

How can I use jsDoc with mobx-state-tree?


I am trying to use jsDoc for my mobx-state-tree powered app but it does not react the way I want.

Visual studio code does not show me the right properties of the corresponding type:

vs-code lists wrong properties

jsDoc is a huge help when it comes to refactoring and keeping js code bug free! But how can I make use of it in this case?

I found this, but it seems it's not really used by anyone: https://github.com/Feverqwe/mst-jsdoc-gen

I really wonder how other devs are dealing with this!


Solution

  • The problem is that your jsDoc is not referring to the instance of the type, but to the type itself.

    Try this instead:

    /**
     * @param {typeof Step.Type} step
     */
    async applyStep(step){}
    

    Or this (as pointed out in the typescript section of the docs):

    /**
     * @param {Instance<typeof Step>} step
     */
    async applyStep(step){}