An error occuren when merge axios config: config.signal.addEventListener is not a function
ZLY201 opened this issue · 3 comments
ZLY201 commented
An error occuren when merge axios config:
config.signal.addEventListener is not a function
You can reproduce it with the following code:
const controller = new AbortController();
cosnt config = deepmerge({}, { signal: controller.signal });
console.log(typeof config.signal.addEventListener); // undefined
console.log(typeof controller.signal.addEventListener); // function
Is this a bug?
RebeccaStevens commented
This library can't merge non-basic objects out of the box.
See https://github.com/TehShrike/deepmerge#ismergeableobject
ZLY201 commented
I found this in the source code:
function getKeys(target) {
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))
}
and something will be wrong with Object.keys
Object.keys(controller.signal) // []
but for...in works fine
for (const key in controller.signal) {
console.log(key);
}
/*
aborted
reason
onabort
throwIfAborted
addEventListener
dispatchEvent
removeEventListener
*/
May be should change to use for...in?
RebeccaStevens commented
There are a few reason why for..in
is a bad approach so I don't see that changing.
If you want a more modern version of this library, check out https://github.com/RebeccaStevens/deepmerge-ts