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

Keeping non-enumerable properties #28

Open
ehmicky opened this issue Jul 30, 2022 · 2 comments
Open

Keeping non-enumerable properties #28

ehmicky opened this issue Jul 30, 2022 · 2 comments

Comments

@ehmicky
Copy link
Contributor

ehmicky commented Jul 30, 2022

At the moment, non-enumerable properties are removed from the return value.

On one hand:

  • Most functional utilities iterate on objects using standard for ... in, Object.keys(...), etc. which ignore non-enumerable properties. Object spreading { ...object } itself removes non-enumerable properties.
  • The concept of a property being non-enumerable implies that it should not be iterated when being copied over.
  • Non-enumerable properties are much less common on plain objects than on class instances, and this library is meant for plain objects.

On the other hand, some users might not expect non-enumerable properties removal as a side effect of this library. For example:

  • excludeKeys(object, ['one']): this would remove object.two if it is non-enumerable, even though the user operation only intended to exclude object.one.
  • includeKeys(object, ['one']): this would not include object.own if it is non-enumerable, even though the user explicitly requested to include it.
  • For predicate functions, the user intent is less clear.

@sindresorhus What are your thoughts on this?

@sindresorhus
Copy link
Owner

By default, I think it makes sense to ignore enumerable properties (it's an edge-case anyway), but I guess it could be useful to add an opt-in option like preserveNonEnumerableProperties.

@sindresorhus
Copy link
Owner

Maybe we should look at what other packages do, like Loads.filter or even https://github.com/tc39/proposal-iterator-helpers

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