{"id":"02f1e863d6f29b8d","repo":"sindresorhus/is","slug":"expected-value-which-is-array-like-received-val","errorCode":null,"errorMessage":"Expected value which is `array-like`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `array-like`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1455,"sourceCode":"\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)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('array-like', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertAsyncFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isAsyncFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncFunction', value));\n\t}\n}\n\nexport function assertAsyncGenerator(value: unknown, message?: string): asserts value is AsyncGenerator {\n\tif (!isAsyncGenerator(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncGenerator', value));\n\t}\n}\n\nexport function assertAsyncGeneratorFunction(value: unknown, message?: string): asserts value is AsyncGeneratorFunction {\n\tif (!isAsyncGeneratorFunction(value)) {","sourceCodeStart":1437,"sourceCodeEnd":1473,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1437-L1473","documentation":"Thrown by `assertArrayLike(value)` when the value fails the library's array-like test: a non-null, non-function object with a valid non-negative safe-integer `length` property. Unlike `assertArray`, this accepts strings, `arguments`, NodeLists, and typed arrays — so failing it means the value has no usable `length` at all.","triggerScenarios":"`assert.arrayLike(value)` receiving null/undefined, numbers, plain objects without `length`, objects with a negative/fractional/NaN `length`, Sets/Maps (which use `size`, not `length`), generators, or functions (explicitly excluded despite having `length`).","commonSituations":"Passing a `Set` or `Map` where a list is expected (they have `size`, not `length`); iterables from generators that were never materialized; JSON objects keyed by index but missing `length`; undefined values from optional chaining on missing response fields.","solutions":["Materialize iterables/Sets first: `Array.from(value)` or `[...value]`.","Fix the upstream source so the value isn't undefined/null (missing field, failed lookup).","If the object is index-keyed, add a correct integer `length` property or convert it to a real array.","If you actually need iteration, assert `assert.iterable` instead of array-like."],"exampleFix":"// before\nconst ids = new Set([1, 2, 3]);\nassert.arrayLike(ids); // Set has .size, not .length — throws\n// after\nassert.arrayLike(Array.from(ids));","handlingStrategy":"type-guard","validationCode":"const isArrayLike = v => v != null && typeof v !== 'function' && Number.isSafeInteger(v.length) && v.length >= 0;\nif (!isArrayLike(value)) { /* handle */ }","typeGuard":"function isArrayLike(value) {\n  return value != null && typeof value !== 'function' &&\n    Number.isSafeInteger(value.length) && value.length >= 0;\n}","tryCatchPattern":"try {\n  assert.arrayLike(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* missing or invalid .length */ }\n  else { throw error; }\n}","preventionTips":["Ensure the object has a non-negative integer length property before asserting","Plain iterables (Set, Map, generators) are not array-like — spread them into an array first","Watch for objects with a length property that is a string or NaN from parsed input"],"tags":["type-assertion","array-like","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}