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
letcurrent: number;
constcontainer = 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
constcontainer = 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
constcontainer = 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
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 setimmutable:strict
will throw an error if the value is set more than onceimmutable:ignore
will simply ignore any set values after the first oneimmutable:strict
is the default behaviour.Example