sindresorhus/is · error · TypeError

Expected value which is `undefined`, received value of type

Error message

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

What it means

Thrown by `assertUndefined()` in @sindresorhus/is when the value is anything other than literal `undefined`. It's a strict `value === undefined` check — `null`, empty string, 0, and false all fail.

Source

Thrown at source/index.ts:1950

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

export function assertUint8Array(value: unknown, message?: string): asserts value is Uint8Array {
	if (!isUint8Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Uint8Array', value));
	}
}

export function assertUint8ClampedArray(value: unknown, message?: string): asserts value is Uint8ClampedArray {
	if (!isUint8ClampedArray(value)) {
		throw new TypeError(message ?? typeErrorMessage('Uint8ClampedArray', value));
	}
}

export function assertUndefined(value: unknown, message?: string): asserts value is undefined {
	if (!isUndefined(value)) {
		throw new TypeError(message ?? typeErrorMessage('undefined', value));
	}
}

export function assertUrlInstance(value: unknown, message?: string): asserts value is URL {
	if (!isUrlInstance(value)) {
		throw new TypeError(message ?? typeErrorMessage('URL', value));
	}
}

// eslint-disable-next-line unicorn/prevent-abbreviations
export function assertUrlSearchParams(value: unknown, message?: string): asserts value is URLSearchParams {
	if (!isUrlSearchParams(value)) {
		throw new TypeError(message ?? typeErrorMessage('URLSearchParams', value));
	}
}

export function assertUrlString(value: unknown, message?: string): asserts value is UrlString {
	if (!isUrlString(value)) {

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. If null should also pass, use `assert.nullOrUndefined(value)` instead.
  2. Trace where the value gets defined — the assertion is telling you initialization/reset logic ran in the wrong order.
  3. Normalize null to undefined at the boundary: `value ?? undefined` only converts nullish, so explicitly map `value === null ? undefined : value` if needed.

Example fix

// before
assert.undefined(map.get(key)); // fails: stored null
// after
assert.nullOrUndefined(map.get(key));
Defensive patterns

Strategy: type-guard

Validate before calling

if (value !== undefined) {
  // clear or reject the value before asserting
}

Type guard

if (is.undefined(value)) {
  // value is undefined here
}

Try / catch

try {
  assert.undefined(value);
} catch (error) {
  if (error instanceof TypeError) { /* value was unexpectedly set */ }
  throw error;
}

Prevention

When it happens

Trigger: `assert.undefined(value)` receiving `null` or any defined value — often used to assert an option/slot has not been set yet, or in exhaustiveness checks.

Common situations: APIs that return `null` where the code expected `undefined` (e.g. DOM getters, JSON round-trips which turn undefined into missing/null); asserting a map slot is empty when a falsy-but-defined default was stored.

Related errors


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