Handling 'defaultValue' Possibly Being 'Undefined' in TypeScript

Hello everyone

const program = (key: string) =>
    Effect.gen(function*() {
        const remoteConfig = yield* Effect.tryPromise(() =>
            admin.remoteConfig().getTemplate(),
        );

        const parameter = remoteConfig.parameters[key];
        const {
            defaultValue
        } = parameter;

        if (isUndefined(defaultValue) || !hasProperty(defaultValue, "value")) {
            yield* Effect.fail(
                new RemoteConfigError({
                    cause: `Remote config key '${key}' not found`,
                }),
            );
        }

        return defaultValue.value;
    });

I am getting an error: 'defaultValue' is possibly 'undefined'.
But why is this not being handled by the checks above?
Was this page helpful?