Enum as @param type in JSDoc

BuZZ-dEE picture BuZZ-dEE · Feb 11, 2014 · Viewed 27.5k times · Source

Is it possible to use an enum for the JSDoc @param type declaration like in the following example?

/**
 * @enum { Number }
 */
var TYPES = {
    TYPE_A: 1,
    TYPE_B: 2
}

/**
 * @param { TYPES } type
 */
function useTypesEnum( type ) {

}

If I use an IDE like Eclipse etc. for JavaScript, there should no warning be raised?

Answer

Ahmed Mahmoud picture Ahmed Mahmoud · Jul 29, 2019

You can achieve that, by doing this:

/**
* @param {(1|2)} type
*/
function useTypesEnum(type) {

}

enter image description here