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

An error occuren when merge axios config: config.signal.addEventListener is not a function #249

Closed
ZLY201 opened this issue Aug 4, 2022 · 3 comments

Comments

@ZLY201
Copy link

ZLY201 commented Aug 4, 2022

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
Copy link

This library can't merge non-basic objects out of the box.
See https://github.com/TehShrike/deepmerge#ismergeableobject

@ZLY201
Copy link
Author

ZLY201 commented Aug 4, 2022

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
Copy link

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

@ZLY201 ZLY201 closed this as completed Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants