I'm trying to add new property to class using decorator. Here is my code
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'
Is there any way to make angular to understand that MyClass
also have newProperty
? Can I do it with .d.ts
file?
this post resolve your problem:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.