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

jshbrntt
  • 5,134
  • 6
  • 31
  • 60
  • Possible duplicate of [How to specify an array of objects as a parameter or return value in JSDoc?](https://stackoverflow.com/questions/14611995/how-to-specify-an-array-of-objects-as-a-parameter-or-return-value-in-jsdoc) – Igor Mar 13 '19 at 18:41

1 Answers1

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

Graham P Heath
  • 7,009
  • 3
  • 31
  • 45