sindresorhus/is · error · TypeError

Expected value which is `infinite number`, received value of

Error message

Expected value which is `infinite number`, received value of type `${is(value)}`.

What it means

Thrown by `assertInfinite()` when `isInfinite()` fails — the value is not exactly `Infinity` or `-Infinity`. This is the inverse of the far more common finite-number check, asserting that a number is specifically infinite.

Source

Thrown at source/index.ts:1665

		throw new TypeError(message ?? typeErrorMessage('Generator', value));
	}
}

export function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction {
	if (!isGeneratorFunction(value)) {
		throw new TypeError(message ?? typeErrorMessage('GeneratorFunction', value));
	}
}

export function assertHtmlElement(value: unknown, message?: string): asserts value is HTMLElement {
	if (!isHtmlElement(value)) {
		throw new TypeError(message ?? typeErrorMessage('HTMLElement', value));
	}
}

export function assertInfinite(value: unknown, message?: string): asserts value is number {
	if (!isInfinite(value)) {
		throw new TypeError(message ?? typeErrorMessage('infinite number', value));
	}
}

export function assertInRange(value: number, range: number | [number, number], message?: string): asserts value is number {
	if (!isInRange(value, range)) {
		throw new TypeError(message ?? typeErrorMessage('in range', value));
	}
}

export function assertInt16Array(value: unknown, message?: string): asserts value is Int16Array {
	if (!isInt16Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Int16Array', value));
	}
}

export function assertInt32Array(value: unknown, message?: string): asserts value is Int32Array {
	if (!isInt32Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Int32Array', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Verify you meant this assertion — most code wants `assertFiniteNumber`; the semantics here are inverted.
  2. If Infinity is a sentinel from config, convert at load time: map `null`/'Infinity' → `Number.POSITIVE_INFINITY` before asserting.
  3. Trace NaN sources (0/0, Infinity - Infinity, parse failures) if you expected an overflow to Infinity.

Example fix

// before
const limit = config.maxItems; // null from JSON
assertInfinite(limit);
// after
const limit = config.maxItems ?? Number.POSITIVE_INFINITY;
assertInfinite(limit);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof value !== 'number' || Number.isFinite(value) || Number.isNaN(value)) {
  throw new TypeError('Expected Infinity or -Infinity');
}

Type guard

function isInfiniteNumber(value: unknown): value is number {
  return value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY;
}

Try / catch

try {
  assert.infinite(value);
} catch (error) {
  if (error instanceof TypeError) { /* got a finite number or NaN where a sentinel Infinity was expected */ }
  else throw error;
}

Prevention

When it happens

Trigger: `is.assert.infinite(value)` with any finite number, `NaN`, a numeric string like `'Infinity'`, or a non-number value.

Common situations: Sentinel-value logic where `Infinity` marks 'no limit' but a config loader parsed it from JSON — JSON cannot represent Infinity, so it arrives as `null` or a string; arithmetic expected to overflow to Infinity instead producing NaN (e.g. `0/0`); mistakenly reaching for `assertInfinite` when `assertFiniteNumber` was intended.

Related errors


AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31). Data as JSON: /data/errors/e1c71b12c9ded338.json. Report an issue: GitHub ↗.