En

@aedge-io/typed-clone

A type-safe, high-performance, and extensible deep cloning library for JavaScript/TypeScript.

前端开发 写业务代码开发Node服务开发全栈应用开发AI应用 通用 ★ 63 Updated 2026-08-02

Install & Use

Copy this prompt and send it to your AI assistant (Claude / Cursor / TRAE / Codex / WorkBuddy etc.) to auto-install:

Help me install this AI Skill: @aedge-io/typed-clone.
It is used for: A type-safe, high-performance, and extensible deep cloning library for JavaScript/TypeScript.
Full Skill content: https://321skill.com/skills/aedge-io-typed-clone/raw/index.md
Read that page and install it.

The prompt includes a link to the full Skill content. You can also view the full content.

This skill addresses the common issues of type loss, poor performance, and inability to clone custom types when performing deep copies of complex objects in JavaScript/TypeScript development. In practice, developers often need to copy complex data structures containing Maps, Sets, Dates, TypedArrays, or even circular references. Built-in methods like JSON.parse(JSON.stringify()) or structuredClone either have type limitations or cannot handle functions or custom classes.

Usage is straightforward: simply install the @aedge-io/typed-clone package via npm or JSR, import the clone function, and then call clone(yourObject) to obtain a type-safe deep copy. For custom classes, you can implement a simple Symbol protocol (the [Clone] method) to let the library know how to clone them, enabling seamless integration.

It is particularly suitable for TypeScript/JavaScript developers who work with heterogeneous, complex data structures, especially those whose projects already use many custom classes, require referential transparency, or wish to avoid writing cumbersome cloning logic manually. For example, in scenarios like state management, data serialization/deserialization, or when creating data snapshots, this library provides a reliable foundational implementation.

We recommend introducing this library early in a project to standardize data cloning practices. Note that it primarily relies on the runtime's structuredClone as a fallback, so the environment must support it (Node.js ≥17, Deno ≥1.14, Bun ≥1.0.0, or browsers with structuredClone support). For types that cannot be cloned (e.g., functions), it explicitly returns a Ref<T> type, alerting the developer that this is a reference requiring special handling in the code.

Key Features

Unlike Lodash's `cloneDeep` or the native `structuredClone`, it clearly encodes—via the TypeScript type system—which types can be cloned and which cannot (returning `Ref<T>`), providing compile-time type safety instead of runtime errors. Additionally, it supports cloning custom types through a simple Symbol protocol, a feature many general-purpose cloning libraries lack.

Limitations

Requires a runtime environment that supports `structuredClone` (Node.js ≥17, Deno ≥1.14, Bun ≥1.0.0, or modern browsers). A polyfill is needed for unsupported environments.

FAQ

What's the difference between typed-clone and JSON.parse(JSON.stringify())?

typed-clone correctly handles functions, Symbols, circular references, TypedArrays, and custom class instances while maintaining type safety, whereas the JSON method loses this information or throws errors.

How do I clone a custom class instance?

Implement the `[Clone]` method (using the library-provided `Clone` symbol) on your class, which should return a new instance.

Installation guide for AI assistants

If your AI coding assistant (Claude Code, Cursor, TRAE etc.) can see this page, send it this message to auto-install:

Visit https://321skill.com/skills/aedge-io-typed-clone/raw/index.md to read the original Skill definition (Markdown format) for @aedge-io/typed-clone, and install it according to the instructions.