We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9699b6b commit 7c99b4fCopy full SHA for 7c99b4f
src/lib/justClone.ts
@@ -29,17 +29,15 @@ export function clone<T>(obj: T): T {
29
// @ts-expect-error Known type
30
return RegExp(obj.source, (obj as RegExp).flags);
31
}
32
- if (type == 'Array') {
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- const result = [] as any;
+ if (type == 'Array' || type == 'Object') {
+ const result = type == 'Object' ? Object.create(Object.getPrototypeOf(obj)) : [];
+
35
for (const key in obj) {
36
result[key] = clone(obj[key]);
37
38
39
return result;
40
- if (type == 'Object') {
41
- return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
42
- }
43
44
// primitives and non-supported objects (e.g. functions) land here
45
return obj;
0 commit comments