Creates an immutable deep clone.
Values are processed according to their type:
Date, Map, Set, class instances, or objects with null prototype)This function is idempotent at every depth: every cloned object and array is branded internally, so calling it again on a frozen clone, or on any nested member extracted from one, returns the same reference. Members reached through multiple paths, or extracted and re-nested into another structure, keep a stable identity. This makes it safe and efficient to use defensively.
The clone keeps the declared type of value, so a write is refused at run time rather than by the compiler: state
the constraint with DeepReadonly where a holder is to be held to it at compile time.
Circular references are not supported. Do not pass objects with cycles.
The type of the value to be cloned
The value to make immutable
A deeply frozen clone of value, keeping its declared type
RangeError Stack overflow when value contains circular references
Creates an immutable deep clone, validating against a type guard.
Values are processed according to their type:
Date, Map, Set, class instances, or objects with null prototype)Validates value against the guard before freezing:
The guard brands only the top-level clone; nested members carry the default brand, so they remain stable under guard-less immutable calls while a guarded call on a nested member revalidates it.
The clone keeps the type the guard validates, so a write is refused at run time rather than by the compiler: state the constraint with DeepReadonly where a holder is to be held to it at compile time.
Circular references are not supported. Do not pass objects with cycles.
Guards must have stable identity. Use module-level named functions or const lambdas.
The validated type of the returned clone
A deeply frozen clone of value, branded with the guard and typed as the validated type
TypeError When the guard returns false
RangeError Stack overflow when value contains circular references
Creates an immutable deep clone, optionally validating against a type guard.