Hyperlinkv0.8.0-beta.28

Types

Types.DeepMutabletypeeffect/Types.ts:512
DeepMutable<T>

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 }> }
typesMutable
Source effect/Types.ts:5124 lines
export 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]> }