sindresorhus/is · error · TypeError

Invalid number of values

Error message

Invalid number of values

What it means

Thrown by the internal `predicateOnArray` helper (source/index.ts:989) when a multi-value check like `isAll(predicate)` / `isAny(predicate)` is evaluated with zero values. With no values, `every`/`some` would return a vacuous result (true/false with no evidence), so the library requires at least one value.

Source

Thrown at source/index.ts:993

	return getObjectType(value) === 'WeakRef';
}

// eslint-disable-next-line @typescript-eslint/no-restricted-types
export function isWeakSet(value: unknown): value is WeakSet<object> {
	return getObjectType(value) === 'WeakSet';
}

export function isWhitespaceString(value: unknown): value is Whitespace {
	return isString(value) && /^\s+$/v.test(value);
}

type ArrayMethod = (function_: (value: unknown, index: number, array: unknown[]) => boolean, thisArgument?: unknown) => boolean;

function predicateOnArray(method: ArrayMethod, predicate: Predicate, values: unknown[]) {
	validatePredicate(predicate);

	if (values.length === 0) {
		throw new TypeError('Invalid number of values');
	}

	return method.call(values, predicate);
}

function typeErrorMessage(description: AssertionTypeDescription, value: unknown): string {
	return `Expected value which is \`${description}\`, received value of type \`${is(value)}\`.`;
}

function typeErrorMessageNot(description: AssertionTypeDescription, value: unknown): string {
	return `Expected value which is not \`${description}\`, received value of type \`${is(value)}\`.`;
}

type NotAssertionResult<Value, Forbidden, UnknownResult> = Exclude<Value, Forbidden> & ([unknown] extends [Value] ? UnknownResult : unknown);

type NotAssertion<Forbidden, UnknownResult = unknown> = <Value>(value: Value, message?: string) => asserts value is NotAssertionResult<Value, Forbidden, UnknownResult>;

// eslint-disable-next-line @typescript-eslint/no-restricted-types

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Guard the call site: check `items.length > 0` before spreading them into `isAll`/`isAny`, and decide explicitly what an empty list means for your logic.
  2. Pass at least one value argument after the predicate.
  3. If you wanted a reusable guard rather than an immediate check, use the array form `isAll([pred1, pred2])` which returns a type guard.

Example fix

// before
isAll(is.string, ...maybeEmpty); // throws when maybeEmpty is []

// after
if (maybeEmpty.length > 0 && isAll(is.string, ...maybeEmpty)) {
  // all strings
}
Defensive patterns

Strategy: validation

Validate before calling

if (values.length === 0) {
  throw new TypeError('Provide at least one value to check');
}

Type guard

function hasValues<T>(arr: T[]): arr is [T, ...T[]] {
  return arr.length > 0;
}

Prevention

When it happens

Trigger: Calling `isAll(predicate)` or `isAny(predicate)` in evaluator mode with no values after the predicate — often because a spread of an empty array supplied the values: `isAll(is.string, ...items)` where `items.length === 0`.

Common situations: Spreading a dynamically-built list that happens to be empty (empty API response, filtered-out results); forgetting the value arguments entirely and expecting a curried guard back (only the predicates-array overload curries); loops that call the check before data loads.

Related errors


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