Check out this TypeScript Docs example showcasing decorators:
function extendingClassDecorator<T extends {new(...args:any[]):{}}>(constructor:T) {
return class extends constructor {
newProperty = "new property";
hello = "override";
}
}
@extendingClassDecorator
class Greeter {
property = "property";
hello: string;
constructor(m: string) {
this.hello = m;
}
}
console.log(new Greeter("world"));
If you attempt to utilize the newProperty
, a transpiler error will be generated:
Error: Property 'newProperty' does not exist on type 'Greeter'.
To resolve this, how can you type it so the transpiler recognizes that newProperty
is indeed present?