diff --git a/libs/common/src/platform/misc/lazy.ts b/libs/common/src/platform/misc/lazy.ts index fb85b93678..96b4d03364 100644 --- a/libs/common/src/platform/misc/lazy.ts +++ b/libs/common/src/platform/misc/lazy.ts @@ -1,6 +1,7 @@ +const NoValue = Symbol("NoValue"); + export class Lazy { - private _value: T | undefined = undefined; - private _isCreated = false; + private _value: T | typeof NoValue = NoValue; constructor(private readonly factory: () => T) {} @@ -10,11 +11,10 @@ export class Lazy { * @returns The value produced by your factory. */ get(): T { - if (!this._isCreated) { - this._value = this.factory(); - this._isCreated = true; + if (this._value === NoValue) { + return (this._value = this.factory()); } - return this._value as T; + return this._value; } }