tsentials-clone

Deep-clone TypeScript values and domain objects to prevent shared-state mutations.

49|Updated May 12, 2026
One-click install
npx skills add https://github.com/senrecep/tsentials --skill tsentials-clone
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tsentials-clone
Source: https://github.com/senrecep/tsentials/tree/main/.well-known/agent-skills/tsentials-clone
Command: npx skills add https://github.com/senrecep/tsentials --skill tsentials-clone

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of unintended mutations when you need to copy objects in memory, ensuring changes to working data do not affect originals.

Core Features & Use Cases

  • Cloneable<T> custom deep-copy: Implement clone() on domain models to control how each class is copied (e.g., excluding fields, resetting mutable state).
  • deepClone() hybrid deep cloning: Deep-copy arbitrary values via native structuredClone when available, with a robust recursive fallback for environments like React Native / Hermes.
  • cloneArray() for collections: Produce safe working copies of arrays by calling .clone() on each Cloneable element.
  • Use cases: Snapshotting objects before applying business rules, preparing immutable request/response models, cloning nested aggregates, and preserving circular references safely.

Quick Start

Use the tsentials-clone skill to create a safe deep copy of your in-memory object or collection before applying transformations.

Frequently Asked Questions about tsentials-clone

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I deep clone objects in TypeScript without causing shared-state mutations?

Deep cloning in TypeScript prevents shared-state mutations by recursively copying values and domain objects. You implement a Cloneable<T> contract with a clone(): T method to safely copy class instances without side effects.

Does structuredClone work in React Native for copying nested domain models?

structuredClone may be unavailable in React Native and Hermes. A deepClone() function provides a robust recursive fallback to safely copy nested aggregates, Map, Set, and Date objects when native structured cloning fails.

What is the best way to clone arrays of class instances in TypeScript?

Cloning arrays of class instances in TypeScript uses cloneArray() to iterate elements and call .clone() on each Cloneable<T> object. This produces safe working copies of collections while preserving custom class logic and mutable state.

Can I deep copy objects with circular references in TypeScript?

Deep copying objects with circular references in TypeScript is supported by robust recursive cloning logic. It safely preserves circular structures during the deep clone process without throwing errors or causing infinite loops.

How do I snapshot domain objects before applying business rules in TypeScript?

Snapshotting domain objects before applying business rules uses deep cloning to create isolated copies. You implement Cloneable<T> to control how specific classes are copied, ensuring transformations on working data do not affect originals.

What happens when deep cloning unsupported types in TypeScript?

Deep cloning unsupported types gracefully degrades instead of throwing errors. The deepClone() function safely handles known structures like TypedArrays and Error subclasses while returning unsupported values unchanged to prevent application crashes.