Skip to content

Cleanup: Use Object.assign() to create shallow copies #2647

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

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/firestore/src/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ export function makeConstructorPrivate<T extends Function>(
PublicConstructor.prototype = cls.prototype;

// Copy any static methods/members
for (const staticProperty in cls) {
if (cls.hasOwnProperty(staticProperty)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(PublicConstructor as any)[staticProperty] = (cls as any)[staticProperty];
}
}
Object.assign(PublicConstructor, cls);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
return PublicConstructor as any;
}
8 changes: 1 addition & 7 deletions packages/firestore/src/util/obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,5 @@ export function shallowCopy<V>(obj: Dict<V>): Dict<V> {
obj && typeof obj === 'object',
'shallowCopy() expects object parameter.'
);
const result: Dict<V> = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
result[key] = obj[key];
}
}
return result;
return { ...obj };
}