-
Notifications
You must be signed in to change notification settings - Fork 239
@enum
(Available since JSDuck 4.0)
Synopsis:
@enum
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. */
"wise",
/** A foolish decision. */
"fool"
];
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).
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("Ext.data.MyStore", {
alias: "store.mystore",
...
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.
@enum
tag as supported by Google Closure Compiler: https://developers.google.com/closure/compiler/docs/js-for-compiler#tag-enum (JSDuck provides a compatible implementation)