Search code examples
javascriptjavascript-objectsjsdoc

How to document an object with only primitive values?


I would like to document objects that cannot have objects as values using JSDoc.

Example allowed:

{
  position: 'ground',
  age: 0,
  alive: false
}

Example disallowed:

{
  data: [/* ... */]
  people: {/* ... */}
}

Is there any way to do the above?
It could be done for example in an @type.


Solution

  • You can define a custom type using union with @typedef

    @typedef {(number|string|boolean|...)} YourType
    

    Then refering to this type in your object documentation