{"id":"493e16c071776e1b","repo":"sindresorhus/is","slug":"expected-values-which-are-orformatter-format-uni","errorCode":null,"errorMessage":"Expected values which are ${orFormatter.format(uniqueExpectedTypes)}. Received values of type${uniqueValueTypes.length > 1 ? 's' : ''} ${andFormatter.format(uniqueValueTypes)}.","messagePattern":"Expected values which are (.+?)\\. Received values of type(.+?) (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1412,"sourceCode":"\tisWhitespaceString: 'whitespace string',\n} as const;\n\ntype IsMethodName = keyof typeof methodTypeMap;\nconst isMethodNames: IsMethodName[] = keysOf(methodTypeMap);\n\nfunction isIsMethodName(value: unknown): value is IsMethodName {\n\treturn isMethodNames.includes(value as IsMethodName);\n}\n\nexport function assertAll(predicate: Predicate | readonly Predicate[], ...values: unknown[]): void | never {\n\tif (values.length === 0) {\n\t\tthrow new TypeError('Invalid number of values');\n\t}\n\n\tif (!isAll(predicate, ...values)) {\n\t\tconst predicateFunction = predicate as Predicate;\n\t\tconst expectedType = !Array.isArray(predicate) && isIsMethodName(predicateFunction.name) ? methodTypeMap[predicateFunction.name] : 'predicate returns truthy for all values';\n\t\tthrow new TypeError(typeErrorMessageMultipleValues(expectedType, values));\n\t}\n}\n\nexport function assertAny(predicate: Predicate | readonly Predicate[], ...values: unknown[]): void | never {\n\tif (values.length === 0) {\n\t\tthrow new TypeError('Invalid number of values');\n\t}\n\n\tif (!isAny(predicate, ...values)) {\n\t\tconst predicates = Array.isArray(predicate) ? predicate as readonly Predicate[] : [predicate as Predicate];\n\t\tconst expectedTypes = predicates.map(singlePredicate => isIsMethodName(singlePredicate.name) ? methodTypeMap[singlePredicate.name] : 'predicate returns truthy for any value');\n\t\tthrow new TypeError(typeErrorMessageMultipleValues(expectedTypes, values));\n\t}\n}\n\nexport function assertOptional<T>(value: unknown, assertion: (value: unknown, message?: string) => asserts value is T, message?: string): asserts value is T | undefined {\n\tif (!isUndefined(value)) {\n\t\tassertion(value, message);","sourceCodeStart":1394,"sourceCodeEnd":1430,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1394-L1430","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Inspect the reported received types and locate which value(s) don't match — filter, coerce, or fix the upstream producer of those values.","If mixed types are actually valid, switch to `assertAny` or use a predicate array combining the acceptable types.","For clearer failures with custom predicates, use a named function so the message can identify the expectation."],"exampleFix":"// before\nassertAll(is.string, ...['a', 42, 'c']); // throws: expected strings, received string and number\n\n// after\nconst items = raw.map(String); // or fix upstream data\nassertAll(is.string, ...items);","handlingStrategy":"try-catch","validationCode":"const allValid = values.every(v => is.string(v));\nif (!allValid) {\n  const bad = values.filter(v => !is.string(v));\n  // handle bad values yourself\n}","typeGuard":"function allOfType<T>(values: unknown[], predicate: (v: unknown) => v is T): values is T[] {\n  return values.every(predicate);\n}","tryCatchPattern":"try {\n  assert.all(is.string, ...values);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // one or more values had the wrong type; message lists expected vs received types\n    return rejectInput(error.message);\n  }\n  throw error;\n}","preventionTips":["Pre-filter or `.every()`-check heterogeneous collections before asserting over them","When collections come from JSON/user input, validate element types at parse time with a schema rather than deep in business logic","Catch the TypeError at the boundary and surface which values failed — the message already enumerates expected and received types"],"tags":["assertion","type-mismatch","validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}