-
Notifications
You must be signed in to change notification settings - Fork 240
Type Definitions
JSDuck checks that your type definitions (specified like {Number}
) follow a rigid specification.
JSDuck supports a basic syntax which is used throughout ExtJS documentation and the syntax supported by Google Closure Compiler.
This list covers what you can do with the basic syntax:
-
{Ext.Element}
- a single Ext.Element. -
{String[]}
- array of strings. -
{String[][]}
- 2D array of strings. -
{Number/String/Boolean}
- either number, string, or boolean. -
{Boolean...}
- variable number of boolean arguments.
These of course can be combined. For example:
-
{String[]/Number[]...}
- variable number of string or number arrays.
For more expressive power Google Closure Compiler Type Expressions allow you to write complex type expressions like this:
-
{function((number|string), RegExp=): boolean}
- a function taking two arguments (first a number or string, second a RegExp which is optional) and returning a boolean.
JSDuck will also check that you don't reference any unknown types. For example if you specify {Foo}
and you don't have class Foo included to you documentation, JSDuck will produce a warning. Warnings aren't thrown for JavaScript primitive types:
boolean
number
string
undefined
void
for built-in JavaScript types:
Object
String
Number
Boolean
RegExp
Function
Array
Arguments
Date
Error
and for few DOM types:
HTMLElement
XMLElement
NodeList
TextNode
CSSStyleSheet
CSSStyleRule
Event
To make JSDuck ignore some other type names use --external=Foo,Bar,...
To document a variable that can be of any type whatsoever, use the Mixed
type. But try to keep its use to the minimum, always prefer the {Foo/Bar/Baz}
syntax to list possible types.