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
- Verify you meant this assertion — most code wants `assertFiniteNumber`; the semantics here are inverted.
- If Infinity is a sentinel from config, convert at load time: map `null`/'Infinity' → `Number.POSITIVE_INFINITY` before asserting.
- 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
- `infinite` means exactly ±Infinity — finite numbers and NaN both fail; use `is.number` for general numbers
- Check `value === Infinity || value === -Infinity` before asserting
- Watch arithmetic that silently produces NaN (0/0, Infinity - Infinity) instead of Infinity
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
- Expected value which is `Date`, received value of type `${is
- Expected value which is `even integer`, received value of ty
- Expected value which is `finite number`, received value of t
- Expected value which is `in range`, received value of type `
- Expected value which is `integer`, received value of type `$
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/e1c71b12c9ded338.json.
Report an issue: GitHub ↗.