Array。<number>或Array <number>?

时间:2019-03-13 17:47:14

标签: javascript jsdoc jsdoc3

数组符号的正确JSDoc格式是什么?

Array.<number>Array<number>

我看过两者可以互换使用,不知道是否有区别。

Promise<number>上也可以使用Promise.<number>吗?

1 个答案:

答案 0 :(得分:2)

关闭编译器使用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