{"id":"7bcf7ece2266f2c5","repo":"sindresorhus/is","slug":"expected-value-which-is-uint8array-received-val","errorCode":null,"errorMessage":"Expected value which is `Uint8Array`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Uint8Array`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1938,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('TypedArray', value));\n\t}\n}\n\nexport function assertUint16Array(value: unknown, message?: string): asserts value is Uint16Array {\n\tif (!isUint16Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint16Array', value));\n\t}\n}\n\nexport function assertUint32Array(value: unknown, message?: string): asserts value is Uint32Array {\n\tif (!isUint32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint32Array', value));\n\t}\n}\n\nexport function assertUint8Array(value: unknown, message?: string): asserts value is Uint8Array {\n\tif (!isUint8Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint8Array', value));\n\t}\n}\n\nexport function assertUint8ClampedArray(value: unknown, message?: string): asserts value is Uint8ClampedArray {\n\tif (!isUint8ClampedArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint8ClampedArray', value));\n\t}\n}\n\nexport function assertUndefined(value: unknown, message?: string): asserts value is undefined {\n\tif (!isUndefined(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('undefined', value));\n\t}\n}\n\nexport function assertUrlInstance(value: unknown, message?: string): asserts value is URL {\n\tif (!isUrlInstance(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('URL', value));","sourceCodeStart":1920,"sourceCodeEnd":1956,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1920-L1956","documentation":"Thrown by `assertUint8Array()` in @sindresorhus/is when the value fails the `isUint8Array` check. Note that Node.js Buffer IS a Uint8Array subclass and passes; plain arrays, ArrayBuffers, and other views do not.","triggerScenarios":"`assert.uint8Array(value)` with an ArrayBuffer, a plain array of bytes, a base64 string, a DataView, or a Blob.","commonSituations":"Web crypto / fetch code where `response.arrayBuffer()` returns an ArrayBuffer that was passed on unwrapped; file contents read as string instead of buffer; byte data arriving base64-encoded from an API.","solutions":["Wrap ArrayBuffers: `new Uint8Array(arrayBuffer)`.","Decode strings first: `new TextEncoder().encode(str)` or `Buffer.from(str, 'base64')`.","For Blobs, await `blob.bytes()` (or `new Uint8Array(await blob.arrayBuffer())`)."],"exampleFix":"// before\nconst data = await response.arrayBuffer();\nassert.uint8Array(data);\n// after\nconst data = new Uint8Array(await response.arrayBuffer());\nassert.uint8Array(data);","handlingStrategy":"type-guard","validationCode":"if (!is.uint8Array(value)) {\n  value = value instanceof ArrayBuffer ? new Uint8Array(value) : Uint8Array.from(value);\n}","typeGuard":"if (is.uint8Array(value)) {\n  // value is Uint8Array here\n}","tryCatchPattern":"try {\n  assert.uint8Array(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* handle non-Uint8Array */ }\n  throw error;\n}","preventionTips":["Wrap raw ArrayBuffers in new Uint8Array(buffer) before asserting — a buffer is not a view","Note Node Buffer IS a Uint8Array subclass and passes, but a DataView does not","Normalize all binary inputs to Uint8Array at the boundary"],"tags":["typescript","type-assertion","typed-array","binary-data"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}