69

Is there a list somewhere of valid types for param tags for jsdoc? For example,

@param {type} myParam Some parameter description

I know that things like number and String are valid, but what if I want to document that the number is an integer. Is int valid?

I've done some googling, but I can't seem to find a full list.

Jeff Storey
  • 56,312
  • 72
  • 233
  • 406

2 Answers2

42

The JS Documentation tooling I've used just tokenizes the comments into strings anyway, making it possible to put anything you want in the {type} section.

You could stick with JavaScript types if you wanted like {number} or {string}, or if you want to specify you could do {integer}... but I would probably recommend something like:

@param {number} myParam must be an integer

cheers

Stephen M Irving
  • 1,324
  • 9
  • 20
hunterloftis
  • 13,386
  • 5
  • 48
  • 50
  • 4
    I have noticed that tools are generally just tokenizing the strings, so it doesn't really matter. I just was hoping that there was some standard set of types. The javascript type system doesn't seem expressive enough (e.g. Number isn't very specific), but there are options as you've shown above. – Jeff Storey Jan 03 '13 at 01:27
  • 4
    One can put anything inside the {}, but it might be nice to know what the conventions are, no? Is there really no list? Like is there a convention for specifiying a Prototype object, or should that be @param {Object} ... ? – fraxture Oct 07 '14 at 09:24
  • 3
    For the JSDoc generator (https://github.com/jsdoc3/jsdoc), in http://usejsdoc.org/tags-param.html is said, "The parameter type can be a built-in JavaScript type, such as string or Object, or a JSDoc namepath to another symbol in your code." In case of a symbol in your code, a link is generated to its definition. However, the built-in types still show up as strings, so there is no real difference e.g. between `{string}` and `{String}`. Also, e.g., PhpStorm recognizes them both, but complains about `{array}` while accepting `{Array}`. – Jānis Elmeris Apr 28 '17 at 15:23
36

To answer the actual question

Is there a list somewhere of valid types for param tags for jsdoc?

The documentation of @param states here that you can use built-in types and "namepaths" (a.k. paths to types you have created/documented earlier and your own types you declared with @type.

If you look up built-in Javascript types, you get the following, for example here, you get the list of primitive types:

  • Boolean
  • Null
  • Undefined
  • Number
  • String
  • Symbol (new in ECMAScript 2015)
  • Object

And here are some examples of namepaths:

  • exampleFunction
  • exampleClass#someInstanceMember
  • exampleClass.staticMember
  • exampleClass~innerMember

E.g. @param {exampleClass} exampleParam Instance of your example class

Gyuri
  • 4,548
  • 4
  • 34
  • 44