sindresorhus/is · warning · TypeError

Expected value which is `NaN`, received value of type `${is(

Error message

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

What it means

Thrown by `assertNan()` (source/index.ts:1711) when `Number.isNaN(value)` is false — this assert requires the value to literally BE NaN, the opposite of the usual 'not NaN' check. It exists for code paths (tests, sentinel handling) that expect a NaN result.

Source

Thrown at source/index.ts:1713

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

export function assertIterable<T = unknown>(value: unknown, message?: string): asserts value is Iterable<T> {
	if (!isIterable(value)) {
		throw new TypeError(message ?? typeErrorMessage('Iterable', value));
	}
}

export function assertMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {
	if (!isMap(value)) {
		throw new TypeError(message ?? typeErrorMessage('Map', value));
	}
}

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

export function assertNativePromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {
	if (!isNativePromise(value)) {
		throw new TypeError(message ?? typeErrorMessage('native Promise', value));
	}
}

export function assertNegativeInteger(value: unknown, message?: string): asserts value is number {
	if (!isNegativeInteger(value)) {
		throw new TypeError(message ?? typeErrorMessage('negative integer', value));
	}
}

export function assertNegativeNumber(value: unknown, message?: string): asserts value is number {
	if (!isNegativeNumber(value)) {
		throw new TypeError(message ?? typeErrorMessage('negative number', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. If you meant 'must be a real, usable number', use `assertNumber()` (which in this library excludes NaN) instead of `assertNan()`.
  2. If you genuinely expect NaN, check why the computation produced a real value instead (e.g. 1/0 gives Infinity, not NaN).
  3. Remember `assertNan` uses non-coercing `Number.isNaN` — pass the numeric result, not a raw string.

Example fix

// before — intended to validate a usable number
assertNan(input); // throws for every valid number!
// after
assertNumber(input); // excludes NaN in this library
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isNaN(value)) {
  // value is a real number or non-number — this assert expects literally NaN
}

Type guard

const isNaNValue = (v: unknown): v is number => typeof v === 'number' && Number.isNaN(v);

Prevention

When it happens

Trigger: Calling `assertNan()` with any valid number, a non-number (strings never pass — `Number.isNaN` does not coerce, so even 'foo' fails), null, or undefined.

Common situations: The most common hit is a semantic mix-up: developers call `assertNan(value)` intending to assert the value is a number that is NOT NaN. Also tests asserting a computation produced NaN when it actually produced Infinity or 0, and expecting the coercing global `isNaN('foo') === true` behavior — `Number.isNaN('foo')` is false.

Related errors


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