Javascript 动态附加属性(VSCode)的JSDoc
我有一个基于参数添加动态属性的类的构造函数:Javascript 动态附加属性(VSCode)的JSDoc,javascript,visual-studio-code,jsdoc,Javascript,Visual Studio Code,Jsdoc,我有一个基于参数添加动态属性的类的构造函数: class Foo { constructor(attach) { for (const key in attach) { this[key] = attach[key]; } } } class Bar { getBar() { return "bar"; } } const foo = new Foo({ bar: new Bar() }) conso
class Foo {
constructor(attach) {
for (const key in attach) {
this[key] = attach[key];
}
}
}
class Bar {
getBar() { return "bar"; }
}
const foo = new Foo({
bar: new Bar()
})
console.log(foo.bar.getBar());
这些属性只是注入的属性的简写
我想以某种方式记录Foo,以便调用站点能够获得良好的自动完成
我尝试了下面代码的一些变体,但VSCode仍然无法在Foo实例中找到t的属性:
/**
* Foogler
* @template {{[key:string]: Bar}} T
* @type {Foo & T}
*/
class Foo {
/**
* Creates a new Foo
* @param {T} attach
*/
constructor(attach) {