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