• If value is undefined, it returns the defaultValue, or throws an exception. Else returns the not-undefined value.

    Type Parameters

    • T

    Parameters

    • value: undefined | T

      value to assert if defined

    • paramName: string

      the parameter name used in the error message

    • OptionaldefaultValue: T

      default value when undefined value is passed in

    Returns T

    defined value

    const value1 = undefined;
    const value2 = 'validString';
    const defaultString = 'defaultString';
    const param = 'stringParam';

    validateDefined(value1, param, defaultString); // 'defaultString'
    validateDefined(value1, param, undefined); // Error: stringParam undefined
    validateDefined(value2, param, defaultString); // 'validString'
    validateDefined(value2, param, undefined); // 'validString'