1

What is the correct JSDoc format for the array notation?

Array.<number> or Array<number>?

I've seen the two used interchangeably and do not know if there's a difference.

Also when it comes to Promise<number> can I also use Promise.<number>?

1

1 Answer 1

2

Closure compiler uses Array<number>. It's possible other flavors of JSDocs prefer Array.<number>, but I haven't worked with them.

eg:

/**
 * Sorts an array of objects by the specified object key and compare
 * function. If no compare function is provided, the key values are
 * compared in ascending order using <code>goog.array.defaultCompare</code>.
 * This won't work for keys that get renamed by the compiler. So use
 * {'foo': 1, 'bar': 2} rather than {foo: 1, bar: 2}.
 * @param {Array<Object>} arr An array of objects to sort.
 * @param {string} key The object key to sort by.
 * @param {Function=} opt_compareFn The function to use to compare key
 *     values.
 */
goog.array.sortObjectsByKey = function(arr, key, opt_compareFn) {
  goog.array.sortByKey(arr, function(obj) { return obj[key]; }, opt_compareFn);
};

Via - https://github.com/google/closure-library/blob/master/closure/goog/array/array.js#L1194

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

Comments

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.