Typescript: new object by constructor

Created on 19 Feb 2015  ·  1Comment  ·  Source: microsoft/TypeScript

I get following error:

TS2351 Cannot use 'new' with an expression whose type lacks a call or construct signature.


class A {
constructor() { ... }
refresh() { return new this.constructor; }
}

new this.constructor works in pure JS.

Thanks:)

By Design

Most helpful comment

The type of constructor is just Function, unfortunately. You can write this instead:

class A { constructor() {  } refresh() { return new (<typeof A>this.constructor); } } 

>All comments

The type of constructor is just Function, unfortunately. You can write this instead:

class A { constructor() {  } refresh() { return new (<typeof A>this.constructor); } } 
Was this page helpful?
0 / 5 - 0 ratings