前景提要
这是为类的方法写的装饰器函数 function autoSave (_target: BookmarkModel, _name: string, descriptor: PropertyDescriptor): PropertyDescriptor { const value = descriptor.value descriptor.value = function (...args: never): boolean { const ret = value.apply(this, args) if (ret === true) { this.save() } return ret } return descriptor }
代码强行执行是完全 OK 的,但是 this.save()这行报个错:
类型“PropertyDescriptor”上不存在属性“save”。
this.save()实际就是执行类实例上的 save 方法完全没问题,但现在这样我就很懵,怎么解决