【发布时间】:2020-06-26 06:00:22
【问题描述】:
考虑一个通用集合:
/**
* A collection of items of the same type
* @template TSingleItem
* */
class ItemsCollection {
/** @type {TSingleItem[]} **/
get items() {
return [createSingleItem()];
}
/**
* Creates a new item based on the implementation type
* @param {string} param
* @returns {TSingleItem}
*/
createSingleItem(param) {
throw new Error("Pure virtual method call!");
}
}
现在我们将其实现为:
class Item {
constructor(name) {
this.name = name;
}
}
class Items extends ItemsCollection {
createSingleItem(param) {
return new Item(param);
}
}
我如何告诉 JSDoc 假设该继承类上的 items 是 Item[] 而不是 TSingleItem[]?
我在课堂上试过这个:
/**
* @extends {ItemsCollection<Item>}
* */
class Items extends ItemsCollection
至少在视觉工作室中没有帮助。什么是正确的语法?如果它与 Visual Studio intellisense 一起使用,则会获得奖励积分。
【问题讨论】:
标签: javascript ecmascript-6 jsdoc