Skip to content
nene edited this page Mar 21, 2012 · 5 revisions

Type definitions (specified like {Number/String}) must follow a rigid specification.

JSDuck supports a basic syntax which is used throughout ExtJS documentation and the syntax supported by Google Closure Compiler.

The basic syntax

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.

Google Closure Compiler Type Expressions

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.

Type names

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.

Clone this wiki locally