I'm trying to spread an Error so that I can alter the error without affecting the original error.
const error = new Error('Error test');
const freeError = {...error};
console.log(error, freeError);
But the output is an empty object {}
. I'm expecting the freeError
have at least a message property, but there is none.
Is this a part of JavaScript feature or is there something wrong with my code or engine?
I know a way to fix this, but it requires an extra work {...error, message: error.message}
. So, yeah, all I need is a clarification so that I can be sure that I am not missing something. Thank you.