Skip to main content
Module

x/rimbu/mod.ts>Deep.protect

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Deep.protect
import { Deep } from "https://deno.land/x/rimbu@0.14.0/mod.ts";
const { protect } = Deep;

Returns the same value wrapped in the Protected type.

Examples

Example 1

const obj = Deep.protect({ a: 1, b: { c: true, d: [1] } })
obj.a = 2        // compiler error: a is readonly
obj.b.c = false  // compiler error: c is readonly
obj.b.d.push(2)  // compiler error: d is a readonly array
(obj as any).b.d.push(2)  // will actually mutate the object

Parameters

source: T
  • the value to wrap