We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have documented the question more on Stack Overflow (http://stackoverflow.com/questions/28150967/typescript-cloning-object)
Is there a way to clone an object in typescript? Currently I'm using the following hack
var cloneObj = new this.constructor();
but typescript raises the following error : error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
The text was updated successfully, but these errors were encountered:
Can you clarify exactly what the issue you're getting with your current answer is?
Sorry, something went wrong.
The problem is that the compiler rises an error when I try to call a constructor dynamically.
var cloneObj = new this.constructor(); // error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
The way I found to make the compiler 1.3 happy was
var cloneObj = new (<any> this.constructor());
But that method does not work with 1.4.1.
Is there a way to call a constructor dynamically?
Using your code from SO any of these casts work with the latest bits and should have on every version since:
var cloneObj = new (<any>this.constructor()); var cloneObj = new (<any>this.constructor)(); var cloneObj = new (<any>this).constructor();
No branches or pull requests
I have documented the question more on Stack Overflow (http://stackoverflow.com/questions/28150967/typescript-cloning-object)
Is there a way to clone an object in typescript? Currently I'm using the following hack
var cloneObj = new this.constructor();
but typescript raises the following error : error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
The text was updated successfully, but these errors were encountered: