5

JSDoc appears to have 2 different but similar syntaxes for parametrised types. An example of the first syntax is Array.<MyClass> (you can find that here). An example of the second is Array<number> (you can find that here). Why are both syntaxes supported, and is one better than the other?

Star Flow
  • 91
  • 1
  • 4

1 Answers1

4

There is no "better" or "worth" way to document your code. What you see is inconsistency in the documentation on JSDoc. They have backlog item to make it consistent: Clean up examples of type applications, which say the following:

Type applications no longer need to include periods. For example, you can write Array<number> rather than Array.<number>. We should update all of our examples to use the more streamlined syntax.

As of documenting Arrays of objects there is already answer on SO: How to specify an array of objects as a parameter or return value in JSDoc?.

Slava Ivanov
  • 6,666
  • 2
  • 23
  • 34
  • 1
    The text you quoted makes it clear that it's better to omit the dot. This is clearer still in [this GitHub comment](https://github.com/jsdoc3/jsdoc/issues/1375#issuecomment-312524767), which says that "`Promise` is preferable" to `Promise.`. Anyway, you have led me to the answer to my question, so thank you. – Star Flow Dec 16 '17 at 10:41
  • @StarFlow Glad it helped you. Accepting Answers: [How does it work?](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work?answertab=active#tab-top) – Slava Ivanov Dec 16 '17 at 19:16