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? Should shapeType be defined as enum or TypeDef or something else?
Shape.prototype.create = function (shapeType) {
// shapeType can be "rect", "circle" or "ellipse"...
this.type = shapeType;
};
Shape.prototype.getType = function (shapeType) {
// shapeType can be "rect", "circle" or "ellipse"...
return this.type;
};
The second part of the problem is that the possible values of shapeType
is not known in the file that defines shapeType
as whatever you suggest. There are multiple files contributed by several developers who might add to the possible values of shapeType
.
PS: Am using jsdoc3
enum
for the definition and a union for the function parameter:ShapeType|string
. However enums don't support adding subtypes after declaration in Closure-compiler. – Desulphurize