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

x/rimbu/deep/index.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.13.5/deep/index.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