I am having a function that accepts one string parameter. This parameter can have only one of a few defined possible values. What is the best way to document the same? Shoul
This is how the Closure Compiler supports it: you can use "@enum" to define a restricted type. You don't actually have to define the values in enum definition. For instance, I might define an "integer" type like:
/** @enum {number} */
var Int = {};
/** @return {Int} */
function toInt(val) {
return /** @type {Int} */ (val|0);
}
Int is generally assignable to "number" (it is a number) but "number" is not assignable to "Int" without some coercion (a cast).