4
TypeScriptとデコレータでプロパティを定義する方法は?例えばTypeScriptクラスデコレータ - クラスメソッドを追加
私は、このクラスのデコレータがあります
function Entity<TFunction extends Function>(target: TFunction): TFunction {
Object.defineProperty(target.prototype, 'test', {
value: function() {
console.log('test call');
return 'test result';
}
});
return target;
}
そして、それを使用します。このコードは正常に働いていた
test call entity.ts:5
test result entity.ts:18
が、TSC:
@Entity
class Project {
//
}
let project = new Project();
console.log(project.test());
を私はこのコンソールログを持っています返品エラー:
entity.ts(18,21): error TS2339: Property 'test' does not exist on type 'Project'.
このエラーを解決するにはどうすればよいですか?
ありがとう!これができないのはあまりにも悪い –