Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/deep/internal.ts>Deep.Protected

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
type alias Deep.Protected
Re-export
import { type Deep } from "https://deno.land/x/rimbu@1.2.0/deep/internal.ts";
const { Protected } = Deep;

A deep readonly typed version of given type T. Makes all properties or elements read only. It maps types using the following rules:

  • arrays and tuples become readonly counterparts, and all element types are wrapped in Protected if applicable
  • Maps of key type K and value type V become Maps of key type Protected<K> and value type Protected<V>
  • Sets of element type E become Sets of element type Protected<E>
  • Promises of value type E become Promises of value type Protected<E>
  • Objects that have only simple properties (no functions or iterators) will have all the properties as Protected if applicable
  • Any other type will not be mapped
definition: IsAny<T> extends true ? T : T extends readonly any[] & infer A ? readonly [K in keyof A]: Protected<A[K]> : T extends Map<infer K, infer V> ? ReadonlyMap<Protected<K>, Protected<V>> : T extends Set<infer E> ? ReadonlySet<Protected<E>> : T extends Promise<infer E> ? Promise<Protected<E>> : IsPlainObj<T> extends true ? readonly [K in keyof T]: Protected<T[K]> : T