【发布时间】:2020-04-03 00:03:21
【问题描述】:
我正在尝试构建一个在构造函数阶段构建一些动态方法的类,一切正常,但是 VS Code 自动建议不适用于动态方法?我们应该怎么做? 这是codeSandBox
我也试过interface,但还是没有成功
export default class A {
private version = 1;
get getVersion() {
return this.version;
}
private actions = ["approve", "edit", "delete"];
constructor() {
this.actions.forEach(
method =>
(A.prototype[method] = route => {
console.warn(method + " called");
})
);
}
}
const B = new A();
console.warn(B.getVersion);
console.warn(B.approve()) // auto suggestion not available here
【问题讨论】:
标签: javascript typescript class types interface