deepClone()
function deepClone\<T\>(value: T): T;Defined in: src/lib/utils.ts:216
Deep clone a value, creating a completely independent copy. Recursively clones all nested properties.
Handles:
- Primitives (returned as-is)
- Arrays (recursive element cloning)
- Plain objects (recursive property cloning)
- null/undefined (returned as-is)
- Date objects (creates new Date with same time)
Does NOT handle (throws TypeError):
- Classes with prototypes (other than Object/Array/Date)
- Functions
- Symbols
- Maps/Sets
- Circular references (will cause stack overflow)
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | T | The value to clone |
Returns
T
A deep copy of the value
Throws
If the value contains unsupported types
Example
const original = { a: 1, b: { c: [1, 2, 3] } };
const cloned = deepClone(original);
cloned.b.c.push(4);
console.log(original.b.c); // [1, 2, 3] - unchanged