Массив. <number>или Массив <number>? - PullRequest
1 голос
/ 13 марта 2019

Какой правильный формат JSDoc для обозначения массива?

Array.<number> или Array<number>?

Я видел, как они используются взаимозаменяемо, и не знаю, есть ли разница.

Также, когда дело доходит до Promise<number>, могу ли я также использовать Promise.<number>?

1 Ответ

2 голосов
/ 14 марта 2019

Компилятор закрытия использует Array<number>. Возможно, другие разновидности JSDocs предпочитают Array.<number>, но я с ними не работал.

например:

/**
 * 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);
};

Через - https://github.com/google/closure-library/blob/master/closure/goog/array/array.js#L1194

...