我正在编写一些 JavaScript 模块,试图让智能感知通过 JsDocs 在 VsCode 上工作
但现在我正在努力尝试为以下情况编写 JsDoc:
假设我有这门课
class SomeClass extends Array {}
class SomeOtherClass extends String {}
我想创建这个函数来扩展它们
function WithFeature(base) {
return class extends base {
constructor() {
super(...arguments)
}
feature(){
// do something...
}
}
}
这样我就可以制作更多很酷的课程
class CoolClass extends WithFeature(SomeClass) {
// ...
}
class OtherCoolClass extends WithFeature(SomeOtherClass) {
// ...
}
如何才能 JsDoc 我的美丽
WithFeature
?
我以为这样的东西会起作用
/**
* @template {T}
* @param {new () => T} base
* @returns {new () => T}
*/
function WithFeature(base) {
// ...
}
或者也许是这个
/** @type {<T>(base: T) => new () => T} */
function WithFeature(base) {
// ...
但是当然它对我不起作用(即它没有在 VsCode 上显示智能感知提示)否则我不会问这个问题!
其他人也遇到过同样的戏剧吗?
您可以使用此格式:
**
* WithFeature
* @param {class} base base class
* @returns {class} new class that extends base
*/
function WithFeature(base) {
return class extends base {
constructor() {
super(...arguments);
}
feature() {
// do something...
}
};
}