ts-data-forge
    Preparing search index...

    Function isNonNegative

    • Type guard that checks if a number is non-negative (greater than or equal to zero).

      When this function returns true, TypeScript narrows the type to exclude negative values, which is useful for operations that require non-negative inputs like array indices or measurements.

      Type Parameters

      • N extends number

        The numeric literal type or number type to check

      Parameters

      • num: N

        The number to check

      Returns num is number & {
          "> -2^16": true;
          "> -2^32": true;
          ">= -2^15": true;
          ">= -2^31": true;
          ">=0": true;
          NaNValue: false;
      } & Readonly<
          {
              "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
          },
      > & RelaxedExclude<N, NegativeIndex<1024>>

      true if the number is >= 0, false otherwise

      const candidate = 10;

      if (Num.isNonNegative(candidate)) {
      const index: number = candidate;

      assert.isTrue(index === 10);
      }

      assert.isFalse(Num.isNonNegative(-1));