According to ES2017 spec the message
property of Error
is non-enumerable. I'm wondering why so?
With non-enumerable property message
it's impossible for example to spread the Error
object like
const payload = new Error('oops!');
// Few lines after
const nextState = {
...payload
};
This especially useful when working with Redux and SFA(Standard Flux Actions).
SFA allows the payload of an action to be an Error
object.
Such action can be processed by a reducer like
// e.g. with redux-actions library
// that provides `handleActions` helper
export default handleActions({
[ERROR_ACTION]: (state, ({ payload }) => ({ ...state, ...payload })
}, initialState)
But because of message
property of Error
is non-enumerable the payload from the code above won't be spreaded.
Has anyone a good answer for this?