UNPKG

@eklabdev/blingts4

Version:

A comprehensive TypeScript decorators library implementing Stage 2 decorators for TS 4.9+

23 lines (22 loc) 696 B
/** * Makes all properties of a class read-only */ export function Immutable() { return function (target) { // Create a subclass that extends the original class return class extends target { constructor(...args) { super(...args); // Make all properties read-only Object.keys(this).forEach(key => { Object.defineProperty(this, key, { writable: false, configurable: false, }); }); // Prevent adding new properties Object.preventExtensions(this); } }; }; }