effect-io-ai

Package: effect
Module: Types

Types.DeepMutable

Recursively removes readonly from all properties, including nested objects, arrays, Map, and Set.

When to use

Use when you need a fully mutable version of a deeply readonly type.

Details

Recursion stops at primitives (string, number, boolean, bigint, symbol) and functions.

Example (Converting deeply to mutable types)

import type { Types } from "effect"

type Deep = Types.DeepMutable<{
  readonly a: string
  readonly b: ReadonlyArray<{ readonly c: number }>
}>
// { a: string; b: Array<{ c: number }> }

See

Signature

type DeepMutable<T> = T extends ReadonlyMap<infer K, infer V> ? Map<DeepMutable<K>, DeepMutable<V>>
  : T extends ReadonlySet<infer V> ? Set<DeepMutable<V>>
  : T extends string | number | boolean | bigint | symbol | Function ? T
  : { -readonly [K in keyof T]: DeepMutable<T[K]> }

Source

Since v3.1.0