tguard-js
    Preparing search index...

    Function isDefined

    • Alias for isNonNullish.

      Checks if a value is "defined" (i.e., not null and not undefined). This is a type guard that narrows the type away from null and undefined.

      Type Parameters

      • T

        The type of the input value.

      Parameters

      • x: T

        The value to check.

      Returns x is NonNullable<T>

      true if the value is not null and not undefined, false otherwise.

      This function is different from isEnvDefined. isEnvDefined checks if an environment variable is defined and has a non-empty string value.

      let myValue: string | null = "hello";
      if (isDefined(myValue)) {
      // myValue is now typed as string
      }

      1.0