@nevware21/ts-utils
    Preparing search index...

    Function isDefined

    • Checks if the passed value is defined, which means it is not strictly undefined (and not null). A string value of "undefined" is considered to be defined. When this returns true, TypeScript narrows the type to Exclude<T, undefined>, removing undefined from the type.

      Type Parameters

      • T

        The expected type of the value when it is defined.

      Parameters

      • arg: any

        The value to check

      Returns arg is Exclude<T, undefined>

      true if the value is defined (not null and not undefined), narrowing the type to Exclude<T, undefined>.

      isDefined(null);         // false
      isDefined(undefined); // false
      isDefined("undefined"); // true

      let value = null;
      isDefined(value); // false
      let value = undefined;
      isDefined(value); // false

      isDefined(""); // true
      isDefined(0); // true
      isDefined(new Date()); // true
      isDefined(true); // true
      isDefined(false); // true