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?
-
Why would you expect one to be better than the other?Andrew Li– Andrew Li2017-12-14 22:07:00 +00:00Commented Dec 14, 2017 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– Star Flow2017-12-14 22:13:07 +00:00Commented Dec 14, 2017 at 22:13
1 Answer
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?.
2 Comments
Promise<number> is preferable" to Promise.<number>. Anyway, you have led me to the answer to my question, so thank you.