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?
Asked
Active
Viewed 4,609 times
5

Star Flow
- 91
- 1
- 4
-
Why would you expect one to be better than the other? – Andrew Li Dec 14 '17 at 22:07
-
@Li357: I'm guessing that one syntax is newer than the other and was introduced because it was considered to be better. – Star Flow Dec 14 '17 at 22:13
1 Answers
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 thanArray.<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
-
1The 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. – Star Flow Dec 16 '17 at 10:41`. Anyway, you have led me to the answer to my question, so thank you. -
@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