-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Do not ignore symbol properties #23
Conversation
for (const key of Object.keys(object)) { | ||
if (set.has(key)) { | ||
for (const key of Reflect.ownKeys(object)) { | ||
if (isEnumerable.call(object, key) && set.has(key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike Object.keys()
, Reflect.ownKeys()
also returns symbols. However, it also returns non-enumerable properties, so we need an additional check.
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
const {propertyIsEnumerable: isEnumerable} = Object.prototype; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
propertyIsEnumerable
is also a global function, so the property is renamed to avoid shadowing.
readme.md
Outdated
@@ -48,15 +46,15 @@ The source object to filter properties from. | |||
|
|||
#### filter | |||
|
|||
Type: `(sourceKey, sourceValue, source) => boolean` | |||
Type: `(sourceKey: string | symbol, sourceValue: any, source: object) => boolean` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflect.ownKeys()
returns array indices as strings (like Object.keys()
does), so sourceKey
cannot be a number
.
index.test-d.ts
Outdated
@@ -1,15 +1,17 @@ | |||
import {expectType, expectError} from 'tsd'; | |||
import {includeKeys, excludeKeys} from './index.js'; | |||
|
|||
const propSymbol = Symbol('test'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const propSymbol = Symbol('test'); | |
const propertySymbol = Symbol('test'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c4552a0
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Fixed 👍 |
Thanks :) |
Fixes #21.
This ensures symbol properties are kept.
This is a breaking change since the function predicate passed as argument needs to handle the potential case that the key might be a symbol instead of a string.