Skip to content

Commit 373a2d4

Browse files
committed
fix(utils): clone usage errors
- clone cannot be used when constructors have unknown required parameters (e.g. custom classes) Signed-off-by: Lexus Drumgold <[email protected]>
1 parent e10348e commit 373a2d4

File tree

7 files changed

+39
-46
lines changed

7 files changed

+39
-46
lines changed

src/utils/assign-with.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
OwnPropertyKey
1212
} from '#src/types'
1313
import cast from './cast'
14-
import clone from './clone'
1514
import define from './define'
1615
import descriptor from './descriptor'
1716
import properties from './properties'
@@ -28,23 +27,22 @@ import reduce from './reduce'
2827
type AssignCustomizer = Fn<[any, any, OwnPropertyKey]>
2928

3029
/**
31-
* Assigns own properties of one or more `source` objects to a target object.
30+
* Assigns all enumerable own properties of one or more `source` objects to a
31+
* target object.
3232
*
3333
* A `customizer` is used to produce assigned values. The initial `base` object
3434
* **will not** be modified.
3535
*
3636
* Source objects are applied from left to right. Subsequent sources overwrite
37-
* property assignments of previous sources.
38-
*
39-
* New properties are *defined* rather than *assigned*. Both enumerable and
40-
* non-enumerable properties will be copied from source objects. Inherited
41-
* properties are not copied.
37+
* property assignments of previous sources. New properties are *defined* rather
38+
* than *assigned*.
4239
*
4340
* **Note**: The return type may differ from the actual return value when using
44-
* a `customizer`. Additionally, TypeScript does not track inheritance. The
45-
* return type may also differ from the actual return value when source objects
46-
* contain inherited properties (e.g. `Map`, `Set`). In such cases, the return
47-
* type will include more keys than present on the return value.
41+
* a `customizer`. Additionally, TypeScript does not track enumerability or
42+
* property inheritance. The return type may also differ from the actual return
43+
* value when source objects contain non-enumerable or inherited properties
44+
* (e.g. `Map`, `Set`). In such cases, the return type will include more keys
45+
* than present on the return value.
4846
*
4947
* @see {@linkcode Assign}
5048
* @see {@linkcode AssignCustomizer}
@@ -71,7 +69,7 @@ const assignWith = <T extends Objectify<any>, U extends readonly ObjectCurly[]>(
7169
value: customizer(acc[key], src[key], key)
7270
})
7371
}, acc)
74-
}, cast(clone(base)))
72+
}, cast({ ...base }))
7573
}
7674

7775
export { assignWith as default, type AssignCustomizer }

src/utils/assign.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import type { Assign, ObjectCurly, Objectify } from '#src/types'
77
import assignWith from './assign-with'
88

99
/**
10-
* Assigns own properties of one or more `source` objects to a target object.
11-
* The initial `base` object **will not** be modified.
10+
* Assigns all enumerable own properties of one or more `source` objects to a
11+
* target object. The initial `base` object **will not** be modified.
1212
*
1313
* Source objects are applied from left to right. Subsequent sources overwrite
14-
* property assignments of previous sources.
14+
* property assignments of previous sources. New properties are *defined* rather
15+
* than *assigned*.
1516
*
16-
* New properties are *defined* rather than *assigned*. Both enumerable and
17-
* non-enumerable properties will be copied from source objects. Inherited
18-
* properties are not copied.
19-
*
20-
* **Note**: TypeScript does not track inheritance. The return type may differ
21-
* from the actual return value when source objects contain inherited properties
22-
* (e.g. `Map`, `Set`). In such cases, the return type will include more keys
23-
* than present on the return value.
17+
* **Note**: TypeScript does not track enumerability or property inheritance.
18+
* The return type may differ from the actual return value when source objects
19+
* contain non-enumerable or inherited properties (e.g. `Map`, `Set`). In such
20+
* cases, the return type will include more keys than present on the return
21+
* value.
2422
*
2523
* @see {@linkcode Assign}
2624
* @see {@linkcode assignWith}

src/utils/merge-with.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
OwnPropertyKey
1212
} from '#src/types'
1313
import cast from './cast'
14-
import clone from './clone'
1514
import define from './define'
1615
import descriptor from './descriptor'
1716
import isObjectPlain from './is-object-plain'
@@ -29,8 +28,9 @@ import reduce from './reduce'
2928
type MergeCustomizer = Fn<[any, any, OwnPropertyKey]>
3029

3130
/**
32-
* Recursively merges own properties of one or more `source` objects into a
33-
* target object. The initial `base` object **will not** be modified.
31+
* Recursively merges all enumerable own properties of one or more `source`
32+
* objects into a target object. The initial `base` object **will not** be
33+
* modified.
3434
*
3535
* A `customizer` is be used to produce merged values. Plain object properties
3636
* are merged recursively. Other objects and value types are overridden by
@@ -39,10 +39,11 @@ type MergeCustomizer = Fn<[any, any, OwnPropertyKey]>
3939
* Source objects are applied from left to right. Subsequent sources overwrite
4040
* property assignments of previous sources.
4141
*
42-
* **Note**: TypeScript does not track inheritance. The return type may differ
43-
* from the actual return value when source objects contain inherited properties
44-
* (e.g. `Map`, `Set`). In such cases, the return type will include more keys
45-
* than present on the return value.
42+
* **Note**: TypeScript does not track enumerability or property inheritance.
43+
* The return type may differ from the actual return value when source objects
44+
* contain non-enumerable or inherited properties (e.g. `Map`, `Set`). In such
45+
* cases, the return type will include more keys than present on the return
46+
* value.
4647
*
4748
* @see {@linkcode Merge}
4849
* @see {@linkcode MergeCustomizer}
@@ -89,7 +90,7 @@ const mergeWith = <T extends Objectify<any>, U extends readonly ObjectCurly[]>(
8990
value: customizer(outgoing, incoming, key)
9091
})
9192
}, acc)
92-
}, cast(clone(base)))
93+
}, cast({ ...base }))
9394
}
9495

9596
export { mergeWith as default, type MergeCustomizer }

src/utils/merge.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ import type { Merge, ObjectCurly, Objectify } from '#src/types'
77
import mergeWith from './merge-with'
88

99
/**
10-
* Recursively merges own properties of one or more `source` objects into a
11-
* target object. The initial `base` object **will not** be modified.
12-
*
13-
* Plain object properties are merged recursively. Other objects and value types
14-
* are overridden by assignment.
10+
* Recursively merges all enumerable own properties of one or more `source`
11+
* objects into a target object. The initial `base` object **will not** be
12+
* modified.
1513
*
1614
* Source objects are applied from left to right. Subsequent sources overwrite
1715
* property assignments of previous sources.
1816
*
19-
* **Note**: TypeScript does not track inheritance. The return type may differ
20-
* from the actual return value when source objects contain inherited properties
21-
* (e.g. `Map`, `Set`). In such cases, the return type will include more keys
22-
* than present on the return value.
17+
* **Note**: TypeScript does not track enumerability or property inheritance.
18+
* The return type may differ from the actual return value when source objects
19+
* contain non-enumerable or inherited properties (e.g. `Map`, `Set`). In such
20+
* cases, the return type will include more keys than present on the return
21+
* value.
2322
*
2423
* @see {@linkcode Merge}
2524
* @see {@linkcode mergeWith}

src/utils/omit.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import type { Omit, PropertyKey, Spread } from '#src/types'
77
import cast from './cast'
8-
import clone from './clone'
98
import reduce from './reduce'
109

1110
/**
@@ -34,7 +33,7 @@ const omit = <T, K extends PropertyKey>(
3433
return reduce(keys, (acc, key) => {
3534
Reflect.deleteProperty(acc, key)
3635
return acc
37-
}, cast({ ...clone(target) }))
36+
}, cast({ ...target }))
3837
}
3938

4039
export default omit

src/utils/overwrite-with.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import type { Fn, ObjectCurly, Overwrite, OwnPropertyKey } from '#src/types'
77
import cast from './cast'
8-
import clone from './clone'
98
import define from './define'
109
import descriptor from './descriptor'
1110
import hasOwn from './has-own'
@@ -60,7 +59,7 @@ const overwriteWith = <T extends ObjectCurly, U extends readonly ObjectCurly[]>(
6059
})
6160
: acc
6261
}, acc)
63-
}, cast(clone(base)))
62+
}, cast({ ...base }))
6463
}
6564

6665
export { overwriteWith as default, type OverwriteCustomizer }

src/utils/reverse.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import type { Reverse } from '#src/types'
77
import cast from './cast'
8-
import clone from './clone'
98
import isArray from './is-array'
109
import join from './join'
1110
import split from './split'
@@ -26,7 +25,7 @@ const reverse = <T extends string | readonly unknown[]>(
2625
target: T
2726
): Reverse<T> => {
2827
return isArray(target)
29-
? cast([...clone(target)].reverse())
28+
? cast([...target].reverse())
3029
: cast(join(split(target, '').reverse(), ''))
3130
}
3231

0 commit comments

Comments
 (0)