Skip to content

CloneOptions

CloneOptions = object

Defined in: packages/core/src/object/clone.ts:21

optional descriptors?: boolean

Defined in: packages/core/src/object/clone.ts:73

Whether to copy property attributes — writable, enumerable, configurable, and getters/setters. Defaults to true.

An accessor cannot be deep-copied: its getter and setter are functions, so preserving one shares those functions with the original. Set this to false to read each accessor once and store the result as a plain writable data property, which is what a consumer that intends to overwrite the copy needs.


optional nonEnumerable?: boolean

Defined in: packages/core/src/object/clone.ts:61

Whether to copy non-enumerable properties. Defaults to true.


optional prototype?: "preserve" | "plain"

Defined in: packages/core/src/object/clone.ts:55

"preserve" (default) keeps the original’s prototype, so a class instance clones as an instance of the same class. "plain" produces an ordinary object instead, the way structuredClone does.


optional recursive?: boolean

Defined in: packages/core/src/object/clone.ts:30

Whether to clone nested values too, so the copy shares no reference with the original. Defaults to false.

Recursing costs the whole tree rather than the top level. Cycles and repeated references are preserved: an object reached twice is cloned once and the copy is shared, exactly as the original was.


optional symbolKeys?: boolean

Defined in: packages/core/src/object/clone.ts:58

Whether to copy symbol-keyed properties. Defaults to true.


optional transfer?: readonly ArrayBuffer[]

Defined in: packages/core/src/object/clone.ts:48

ArrayBuffers to move into the clone instead of copying. Each one is detached from the caller, so the original and every view over it become unusable — in exchange the bytes are never copied.

Only an ArrayBuffer can be transferred. The other Transferable types (MessagePort, the stream types, ImageBitmap, …) can only be moved by the host, so passing one throws.

Every entry must be reached by the value being cloned, or it throws. This deliberately differs from structuredClone, which detaches an unreachable entry anyway and then discards it.

Without recursive, only buffers reachable at depth 1 are considered, since nothing deeper is visited.


optional unsupported?: CloneUnsupportedPolicy

Defined in: packages/core/src/object/clone.ts:83

What to do with a value that cannot be copied — a function, a symbol, a WeakMap/WeakSet, a Promise. "throw" (default) reports it, "reference" shares the original, "omit" drops the property holding it.

Only consulted for values actually visited, so a shallow clone never inspects property values and never applies this to them.