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

x/rimbu/deep/internal.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@1.0.2/deep/internal.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