ts-data-forge
    Preparing search index...

    Function isNonZero

    • Type guard that checks if a number is non-zero.

      When this function returns true, TypeScript narrows the type to exclude zero, providing compile-time safety for division operations and other calculations that require non-zero values.

      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; NaNValue: false } & Readonly<
          {
              "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
          },
      > & RelaxedExclude<N, 0>

      true if the number is not zero, false otherwise

      const value: number = 5;

      if (Num.isNonZero(value)) {
      // Safe to divide now that we know value is non-zero
      // eslint-disable-next-line total-functions/no-partial-division
      const inverted = 1 / value;
      assert(inverted === 0.2);
      }

      assert.notOk(Num.isNonZero(0));