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?

2
  • Why would you expect one to be better than the other? Commented 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. Commented Dec 14, 2017 at 22:13

1 Answer 1

6

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?.

Sign up to request clarification or add additional context in comments.

2 Comments

The text you quoted makes it clear that it's better to omit the dot. This is clearer still in this GitHub comment, which says that "Promise<number> is preferable" to Promise.<number>. 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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.