这是我想要得到的非常简单的例子。我的问题是关于@returns 标签。我应该在那里写什么?
class Base{
/**
* @returns {QUESTION: WHAT SHOUL BE HIRE??}
*/
static method(){
return new this()
}
}
class Sub extends Base{
}
let base= Base.method() // IDE should understand that base is instance of Base
let sub= Sub.method() // IDE should understand that sub is instance of Sub
最佳答案
没有“相对”类型。 您可以相当简单地修改扩展类;
/** @extends {Base} */
class Sub extends Base{
/** @returns {Sub} */
static method(){
return super.method();
}
}
或者也许使用第三种类型,一个定义此方法存在的@interface
/** @interface */
class I {
method() {}
}
/** @implements {I} */
class Base {
/** @returns {I} */
static method(){
return new this();
}
}
/**
* @extends {Base}
* @implements {I}
*/
class Sub {
/** @returns {I} */
static method(){
return new this();
}
}
关于javascript - jsdoc如何描述返回SAME CLASS变量的静态类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60980163/