{"id":"7f0848e0ccd38f97","repo":"sindresorhus/is","slug":"expected-value-which-is-array-received-value-of","errorCode":null,"errorMessage":"Expected value which is `Array`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Array`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1436,"sourceCode":"\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);\n\t}\n}\n\nexport function assertArray<T = unknown>(value: unknown, assertion?: (element: unknown, message?: string) => asserts element is T, message?: string): asserts value is T[] {\n\tif (!isArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Array', value));\n\t}\n\n\tif (assertion) {\n\t\tfor (const element of value) {\n\t\t\t// @ts-expect-error: \"Assertions require every name in the call target to be declared with an explicit type annotation.\"\n\t\t\tassertion(element, message);\n\t\t}\n\t}\n}\n\nexport function assertArrayBuffer(value: unknown, message?: string): asserts value is ArrayBuffer {\n\tif (!isArrayBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('ArrayBuffer', value));\n\t}\n}\n\nexport function assertArrayLike<T = unknown>(value: unknown, message?: string): asserts value is ArrayLike<T> {\n\tif (!isArrayLike(value)) {","sourceCodeStart":1418,"sourceCodeEnd":1454,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1418-L1454","documentation":"Thrown by `assertArray(value)` when `Array.isArray(value)` is false. The library uses this assert to narrow `unknown` to `T[]`; the message reports the actual type via `is()` (e.g. 'Object', 'string', 'Set'). An optional per-element assertion runs only after this check passes.","triggerScenarios":"`assert.array(value)` receiving anything that is not a true Array: array-like objects (`arguments`, `NodeList`, `{length: 2}`), typed arrays, Sets, iterables, JSON objects with numeric keys, or a single item where a list was expected. A custom `message` argument replaces the default text.","commonSituations":"API/JSON responses returning a single object instead of an array (or a `{data: [...]}` wrapper being passed whole); DOM `querySelectorAll` results (NodeList, not Array); config files where a scalar was written instead of a YAML/JSON list; ORM results returning a cursor/iterable.","solutions":["Check what the caller actually passes and unwrap it (e.g. pass `response.data`, not `response`).","Convert array-likes/iterables first: `Array.from(value)` or spread `[...value]`.","If array-like is acceptable, use `assert.arrayLike` instead of `assert.array`.","Normalize single-item inputs: `const list = Array.isArray(x) ? x : [x]` before asserting."],"exampleFix":"// before\nassert.array(document.querySelectorAll('li')); // NodeList, throws\n// after\nassert.array(Array.from(document.querySelectorAll('li')));","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(value)) {\n  // reject or normalize before calling assert.array(value)\n}","typeGuard":"function isArrayOf(value, itemPredicate) {\n  return Array.isArray(value) && (!itemPredicate || value.every(itemPredicate));\n}","tryCatchPattern":"try {\n  assert.array(value, is.string);\n} catch (error) {\n  if (error instanceof TypeError) { /* value was not an Array (or items failed) */ }\n  else { throw error; }\n}","preventionTips":["Use is.array(value) as a guard instead of assert.array when a false branch is expected","Remember array-likes (arguments, NodeList) are not Arrays — convert with Array.from first","Don't pass a possibly-single item; wrap with Array.isArray(x) ? x : [x] only if the API contract allows it"],"tags":["type-assertion","array","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}