RedJohn RedJohn - 1 year ago 146
TypeScript Question

Typescript decorate class add new method

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 () {



class Test {
constructor() {
//Property 'someMethod' does not exist on type 'Test'.

Answer Source

You could use:




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...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download