nene edited this page Aug 9, 2012 · 2 revisions

(Available since JSDuck 4.0)


Documentation for enumeration.

@enum {Type}
Documentation for enumeration.

@enum {Type} EnumName
Documentation for enumeration

@enum [EnumName=alias.*]
Documentation for enumeration

Documents an enumeration of values. An enum will show up in documentation as a glorified class, listing its values as properties.


The type and name of enum is auto-detected when doc-comment is followed by assignment of object literal. The values inside the literal can be documented separately:

/** @enum */
MyEnum = {
  /** the first enum value */
  FIRST: 'foo',
  /** the second enum value */
  SECOND: 'bar'

The above code is equivalent to the following:

/** @enum {string} MyEnum */
   * @property {string} [FIRST='foo']
   * the first enum value
   * @property {string} [SECOND='bar']
   * the second enum value

Additionally an enum can be declared using an array. Again, each value can be documented separately:

/** @enum */
My.enum.Smartness = [
    /** A wise choice. */
    /** A foolish decision. */

This kind of enum only works for string values. Also, an enum defined this way will be useful for documentation purposes only - one can't use in code My.enum.SmartNess.wise but instead needs to use the string "wise" directly (it's a common practice JavaScript anyway to use compact strings instead of verbose constant names).

Auto-generation of values

JSDuck provides a handy shortcut for defining enums of class alias names. For example:

 * @enum [My.enums.Store=store.*]
 * All available store types.

This enum will be automatically populated with all the available store types. That is, it will list all the classes which define an alias beginning with "store." like the below class:

/** Some store */
Ext.define("", {
    alias: "store.mystore",

Alternative for small enums

Sometimes you need to define an enumeration of a few values that you need to use in only one or few places. In such case it can be more effective to define the enumeration of values inside the type definition:

 * @cfg {"top"/"bottom"} align
align: "top",

See type definitions guide for details.

See also

@enum tag as supported by Google Closure Compiler: (JSDuck provides a compatible implementation)

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.