2

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.

Kyll
  • 7,036
  • 7
  • 41
  • 64

1 Answers1

2

You can define a custom type using union with @typedef

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

Then refering to this type in your object documentation

user3003238
  • 1,517
  • 10
  • 17
  • It's long and cumbersome but welp, if it works ¯\_(ツ)_/¯ – Kyll Jul 17 '18 at 09:16
  • Ah and what about something like `Object.`? – Kyll Jul 17 '18 at 09:19
  • @PaulStenne Yes, that works as well. Which one is better dependents on your actual need. If that's the only object that require this type and you are sure there will be no non-primitive properties added in the future, I will recommend you do `Object.` – user3003238 Jul 17 '18 at 09:24
  • I thought it is possible to reuse `@typedef` in other modules, but [reading this issue](https://github.com/jsdoc3/jsdoc/issues/1537) discourage me. So is it possible to be reused? – Jordan Enev Jul 17 '18 at 09:27
  • 1
    @JordanEnev I found something that may be helpful to you https://stackoverflow.com/questions/42829250/jsdoc-reference-typedef-ed-type-from-other-module – user3003238 Jul 17 '18 at 09:32