{"id":"5958562a784ea712","repo":"sindresorhus/is","slug":"expected-value-which-is-arraybuffer-received-va","errorCode":null,"errorMessage":"Expected value which is `ArrayBuffer`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `ArrayBuffer`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1449,"sourceCode":"\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)) {\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)) {","sourceCodeStart":1431,"sourceCodeEnd":1467,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1431-L1467","documentation":"Thrown by `assertArrayBuffer(value)` when the value is not an `ArrayBuffer` instance (checked via the library's `isArrayBuffer` object-type tag check). Typed array views, DataViews, Node Buffers, and SharedArrayBuffers all fail this check even though they hold binary data.","triggerScenarios":"Passing a `Uint8Array`, `Buffer`, `DataView`, `SharedArrayBuffer`, or a base64/hex string to code that calls `assert.arrayBuffer(value)`. Also cross-realm ArrayBuffers are fine (tag-based check), but a Node `Buffer` is a Uint8Array view, not an ArrayBuffer, and throws.","commonSituations":"Node.js code passing `fs.readFileSync()` output (a Buffer) where a Web API-style ArrayBuffer is expected; fetch handlers passing `response.body` or a Uint8Array instead of `await response.arrayBuffer()`; WebSocket/crypto APIs mixing views and buffers.","solutions":["If you have a typed array or Buffer, pass its underlying buffer: `view.buffer` (mind `byteOffset`/`byteLength` — slice if the view doesn't cover the whole buffer).","For fetch, use `await response.arrayBuffer()` rather than the body stream.","If any binary view is acceptable, assert with `assert.typedArray` or `assert.dataView` instead.","Convert strings via `new TextEncoder().encode(str).buffer`."],"exampleFix":"// before\nconst data = fs.readFileSync(path);\nassert.arrayBuffer(data); // Buffer is a Uint8Array view, throws\n// after\nconst buf = fs.readFileSync(path);\nassert.arrayBuffer(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof ArrayBuffer)) {\n  // convert: value = typedArray.buffer or Buffer.buffer slice\n}","typeGuard":"const isArrayBuffer = (value) => value instanceof ArrayBuffer;","tryCatchPattern":"try {\n  assert.arrayBuffer(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* got a TypedArray/Buffer/SharedArrayBuffer instead? */ }\n  else { throw error; }\n}","preventionTips":["Distinguish ArrayBuffer from TypedArray views — pass typedArray.buffer when a raw buffer is required","SharedArrayBuffer is not an ArrayBuffer; check which one the API expects","Cross-realm buffers fail instanceof — prefer is.arrayBuffer which uses toString-tag detection"],"tags":["type-assertion","binary-data","arraybuffer"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}