ts-data-forge
    Preparing search index...

    Function isPositive

    • Type guard that checks if a number is positive (greater than zero).

      When this function returns true, TypeScript narrows the type to exclude zero and negative values. This is particularly useful for validating inputs that must be strictly positive, such as dimensions, counts, or rates.

      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 & {
          "!=0": true;
          "> -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, 0 | NegativeIndex<1024>>

      true if the number is > 0, false otherwise

      const amount = 42;

      if (Num.isPositive(amount)) {
      assert.isTrue(amount > 0);
      }

      assert.isFalse(Num.isPositive(0));