Dev Highlights

Доки по разработке

This project is maintained by teniryte

Глубокая неизменяемость

Принципы

Пример

import { Readonly, readonly } from 'ts-cookbook';

const array = readonly([1, 2, 3]);
// array.push(4); // Ошибка: метод отсутствует

class Person {
  constructor(public name: string, public age: number) {}
}

const person = readonly(new Person('Harry', 42));
// person.name = 'Harr'; // Ошибка

const myObj2 = readonly({
  o: { prop: 1 },
  map: new Map([['foo', 'bar']]),
  a: [1, 2, 3],
});

Практика