I want to add a new method to a decorated class. Everything works well but the compiler complains that the method does not exist, how can I satisfy the compiler?
export function decorate( constructor : Function ) {
constructor.prototype.someMethod = function () {
}
}
@decorate
class Test {
constructor() {
//Property 'someMethod' does not exist on type 'Test'.
this.someMethod();
}
}
You could use:
(<any>this).someMethod();
or:
this['someMethod']();
You can't use interfaces to check that this
contains method someMethod()
because you're not in fact implementing the interface so I think these two are the only options...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments