如何在TypeScript(角度)中使用装饰器向类添加和声明新属性

我正在尝试使用装饰器向类添加新属性。这是我的代码

LOAD DATA INFILE 'gs://Bucket_name/pre.txt' INTO TABLE Prep FIELDS TERMINATED BY '\t' LInes TERMINATED BY '\r\n'   IGNORE 1 LInes;

有什么方法可以使您了解function classDecorator<T extends {new(...args: any[]): {}}>(constructor: T) { constructor.prototype.newProperty = 'some value'; } @classDecorator class MyClass { property1: string = 'value1'; property2: string = 'value1'; } const obj = new MyClass(); console.log(obj); console.log(obj.property1); console.log(obj.property2); console.log(obj.newProperty); // error TS2551: Property 'newProperty' does not exist on type 'MyClass' 也有MyClass吗?我可以使用newProperty文件吗?

hzcker 回答:如何在TypeScript(角度)中使用装饰器向类添加和声明新属性

此帖子解决了您的问题:

How to add a new property to a class using class decorator?

本文链接:https://www.f2er.com/3051609.html

大家都在问