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

Related issues

metaweta picture metaweta  路  140Comments

rbuckton picture rbuckton  路  139Comments

yortus picture yortus  路  157Comments

sandersn picture sandersn  路  265Comments

OliverJAsh picture OliverJAsh  路  242Comments