• Creates a container that holds a late initialized value.

    There are three different types of behaviours for that container:

    • mutable will only throw if the value is read before it has been set
    • immutable:strict will throw an error if the value is set more than once
    • immutable:ignore will simply ignore any set values after the first one

    immutable:strict is the default behaviour.

    Example

    let current: number;

    const container = lateInit<number>('mutable');
    current = container.value; // error, not initialized yet
    container.value = 0; // ok, value set to 0
    current = container.value; // ok, current === 0
    container.value = 1; // ok, value set to 1
    current = container.value; // ok, current === 1

    const container = lateInit<number>('immutable:strict');
    current = container.value; // error, not initialized yet
    container.value = 0; // ok, value set to 0
    current = container.value; // ok, current === 0
    container.value = 1; // error, once set changes are not allowed
    current = container.value; // ok, current === 0

    const container = lateInit<number>('immutable:ignore');
    current = container.value; // error, not initialized yet
    container.value = 0; // ok, value set to 0
    current = container.value; // ok, current === 0
    container.value = 1; // ok, but value is ignored without error!
    current = container.value; // ok, current === 0

    Type Parameters

    Type Parameters

    • T

    Parameters

    Returns LateInit<T>

Generated using TypeDoc