Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new object by constructor #2081

Closed
ghost opened this issue Feb 19, 2015 · 1 comment
Closed

new object by constructor #2081

ghost opened this issue Feb 19, 2015 · 1 comment
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@ghost
Copy link

ghost commented Feb 19, 2015

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:)

@RyanCavanaugh RyanCavanaugh added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Feb 19, 2015
@RyanCavanaugh
Copy link
Member

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

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

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

1 participant