Function Frozen

  • When applied to a class it creates a frozen instance of it, thus preventing modifications to instance properties after instantiation.

    Type Parameters

    Parameters

    • cst: T

    Returns T & Newable

    Example

    @Frozen
    class Foo<T> {
    foo: T;
    bar?: MaybeUndefined<string>;

    constructor(foo: T) {
    this.foo = foo;
    this.bar = 'bar';
    }

    someFoo(): T {
    return this.foo;
    }
    }

    const foo = new Foo('foo');
    // The line below will cause a TypeError: Cannot assign to read only property 'bar'
    foo.bar = 'altered bar';
    // The line below will cause a TypeError: Cannot delete property 'bar'
    delete foo.bar;