How can I document a type in webstorm using just jsdoc?

前端 未结 3 1041
有刺的猬
有刺的猬 2020-12-30 02:40

When I write the following code, the annotator tells me that BrowserSelector is not defined in the second typedef:

/**
 * @typedef {{name: Strin         


        
相关标签:
3条回答
  • Multiple comments to describe properties is not necessary as of Webstorm 7 (perhaps earlier).

    /**
     * @name BrowserSelector
     * @type {{
     *     name: String,
     *     minVer: Number,
     *     maxVer: Number
     * }}
     */
    
    0 讨论(0)
  • 2020-12-30 03:26

    I'm using this comment style for 'struct' like types:

    /**
     * @name BrowserSelector
     * @property {String} name
     * @property {Number} minVer
     * @property {Number} maxVer
     */
    
    /** @type {BrowserSelector|*} */
    var mySelector = {}; // no warning because of '*' in @type :S
    mySelector.name = 'foo'; // no warning :)
    mySelector.id = 'bar'; // warning :)
    

    0 讨论(0)
  • 2020-12-30 03:29

    I recently noticed in the AngularJS source code that they also annotated stuff without any directly attached code. I tried the same principle on your case and came up with the following (even code-completion and type checking work with it in WebStorm):

    /**
     * @name BrowserSelector
     */
    /**
     * @name BrowserSelector#name
     * @type {string}
     */
    /**
     * @name BrowserSelector#minVer
     * @type {number}
     */
    /**
     * @name BrowserSelector#maxVer
     * @type {number}
     */
    
    /**
     * @name Selector
     */
    /**
     * @name Selector#type
     * @type {string}
     */
    /**
     * @name Selector#browser
     * @type {BrowserSelector}
     */
    /**
     * @name Selector#attribute
     * @type {Object}
     */
    
    0 讨论(0)
提交回复
热议问题