Skip to main content

structuredClone

Package: @antithrow/std

Non-throwing wrapper around globalThis.structuredClone.

Signature

function structuredClone<T>(
value: T,
options?: StructuredSerializeOptions,
): Settled<T, DOMException>;
ArgumentTypeDescription
valueTValue to clone.
optionsStructuredSerializeOptionsOptional transfer options.

Returns Ok(cloned) on success, Err(DOMException) when value contains non-cloneable data (functions, symbols, DOM nodes without transfer).

Throws

Never.

Example

import { structuredClone } from "@antithrow/std";

const clone = structuredClone({ nested: { value: 1 } });
const bad = structuredClone(() => {}); // Err(DOMException)