Open
Description
Is your feature request related to a problem? Please describe.
I'm not sure this is classified as a bug or a feature request, but maybe rather a proposal thing.
As I wrote in #5922 (comment), I think filtering functions like pick
and omit
should preserve the semantics of the original object as much as possible. Thus the prototype, the property descriptors, and the extensibility should be copied to the result.
Describe the solution you'd like
For example, the code of pick
should be like below:
export function pick<T extends object, K extends keyof T>(
obj: Readonly<T>,
keys: readonly K[],
): Pick<T, K> {
const result = Object.create(Object.getPrototypeOf(obj));
for (const key of keys) {
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
if (descriptor) Object.defineProperty(result, key, descriptor);
}
if (!Object.isExtensible(obj)) Object.preventExtensions(result);
return result;
}
Is this an acceptable change to the APIs? If so, could someone enumerate APIs that should be rewritten?
pick
omit