sindresorhus/is · error · TypeError

Expected values which are ${orFormatter.format(uniqueExpecte

Error message

Expected values which are ${orFormatter.format(uniqueExpectedTypes)}. Received values of type${uniqueValueTypes.length > 1 ? 's' : ''} ${andFormatter.format(uniqueValueTypes)}.

What it means

Thrown by `assertAll` (source/index.ts:1404) when at least one supplied value fails the predicate. The message is built by `typeErrorMessageMultipleValues`, listing the expected type(s) (looked up from the predicate's function name via `methodTypeMap`, or a generic 'predicate returns truthy for all values' for custom predicates) and the distinct detected types of the received values using `Intl.ListFormat`-style 'or'/'and' formatting.

Source

Thrown at source/index.ts:1412

	isWhitespaceString: 'whitespace string',
} as const;

type IsMethodName = keyof typeof methodTypeMap;
const isMethodNames: IsMethodName[] = keysOf(methodTypeMap);

function isIsMethodName(value: unknown): value is IsMethodName {
	return isMethodNames.includes(value as IsMethodName);
}

export function assertAll(predicate: Predicate | readonly Predicate[], ...values: unknown[]): void | never {
	if (values.length === 0) {
		throw new TypeError('Invalid number of values');
	}

	if (!isAll(predicate, ...values)) {
		const predicateFunction = predicate as Predicate;
		const expectedType = !Array.isArray(predicate) && isIsMethodName(predicateFunction.name) ? methodTypeMap[predicateFunction.name] : 'predicate returns truthy for all values';
		throw new TypeError(typeErrorMessageMultipleValues(expectedType, values));
	}
}

export function assertAny(predicate: Predicate | readonly Predicate[], ...values: unknown[]): void | never {
	if (values.length === 0) {
		throw new TypeError('Invalid number of values');
	}

	if (!isAny(predicate, ...values)) {
		const predicates = Array.isArray(predicate) ? predicate as readonly Predicate[] : [predicate as Predicate];
		const expectedTypes = predicates.map(singlePredicate => isIsMethodName(singlePredicate.name) ? methodTypeMap[singlePredicate.name] : 'predicate returns truthy for any value');
		throw new TypeError(typeErrorMessageMultipleValues(expectedTypes, values));
	}
}

export function assertOptional<T>(value: unknown, assertion: (value: unknown, message?: string) => asserts value is T, message?: string): asserts value is T | undefined {
	if (!isUndefined(value)) {
		assertion(value, message);

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Inspect the reported received types and locate which value(s) don't match — filter, coerce, or fix the upstream producer of those values.
  2. If mixed types are actually valid, switch to `assertAny` or use a predicate array combining the acceptable types.
  3. For clearer failures with custom predicates, use a named function so the message can identify the expectation.

Example fix

// before
assertAll(is.string, ...['a', 42, 'c']); // throws: expected strings, received string and number

// after
const items = raw.map(String); // or fix upstream data
assertAll(is.string, ...items);
Defensive patterns

Strategy: try-catch

Validate before calling

const allValid = values.every(v => is.string(v));
if (!allValid) {
  const bad = values.filter(v => !is.string(v));
  // handle bad values yourself
}

Type guard

function allOfType<T>(values: unknown[], predicate: (v: unknown) => v is T): values is T[] {
  return values.every(predicate);
}

Try / catch

try {
  assert.all(is.string, ...values);
} catch (error) {
  if (error instanceof TypeError) {
    // one or more values had the wrong type; message lists expected vs received types
    return rejectInput(error.message);
  }
  throw error;
}

Prevention

When it happens

Trigger: `assertAll(is.string, 'a', 42)` — any call where one or more values do not satisfy the given predicate (or predicate array). Custom anonymous predicates produce the generic 'predicate returns truthy for all values' expected-type text.

Common situations: Mixed-type arrays from loosely-typed sources (JSON payloads, CSV parses, user input) validated as homogeneous; a single null/undefined slipping into an otherwise valid list; schema drift after an API version change.

Related errors


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