{"id":"89002d89407f0d3f","repo":"sindresorhus/is","slug":"expected-value-which-is-typedarray-received-val","errorCode":null,"errorMessage":"Expected value which is `TypedArray`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `TypedArray`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1920,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('symbol', value));\n\t}\n}\n\nexport function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T {\n\tif (!isTruthy(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('truthy', value));\n\t}\n}\n\nexport function assertTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string): asserts value is ResolveTypesOfTypeGuardsTuple<T> {\n\tif (!isTupleLike(value, guards)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('tuple-like', value));\n\t}\n}\n\nexport function assertTypedArray(value: unknown, message?: string): asserts value is TypedArray {\n\tif (!isTypedArray(value)) {\n\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));","sourceCodeStart":1902,"sourceCodeEnd":1938,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1902-L1938","documentation":"Thrown by `assert.typedArray()` (assertTypedArray at source/index.ts:1918) when the value is not one of the TypedArray views (Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array). Notably, plain arrays, `ArrayBuffer`, and `DataView` all fail — a buffer is not a view, and DataView is not a TypedArray.","triggerScenarios":"Calling `assert.typedArray(value)` with a plain number array (`[1,2,3]`), a raw `ArrayBuffer`, a `DataView`, or a Node `Buffer`-like structure round-tripped through JSON (which becomes `{type:'Buffer',data:[...]}`).","commonSituations":"Binary data from fetch/fs handled as ArrayBuffer without wrapping in a view; JSON-serialized buffers from APIs arriving as plain objects; wanting DataView semantics — DataView deliberately does not pass this check; plain arrays of bytes from user code.","solutions":["Wrap raw buffers in a view: `new Uint8Array(arrayBuffer)` before asserting.","Convert plain arrays with `Uint8Array.from(array)` (or the appropriate element type).","If serialized Node Buffer JSON (`{type:'Buffer',data}`) is the input, reconstruct via `Uint8Array.from(obj.data)`; for DataView use `assert.dataView()` instead."],"exampleFix":"// before\nconst data = await response.arrayBuffer();\nassert.typedArray(data);\n// after\nconst data = new Uint8Array(await response.arrayBuffer());\nassert.typedArray(data);","handlingStrategy":"type-guard","validationCode":"if (!ArrayBuffer.isView(value) || value instanceof DataView) {\n  throw new TypeError('Expected a TypedArray');\n}","typeGuard":"function isTypedArray(value: unknown): value is Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array {\n  return ArrayBuffer.isView(value) && !(value instanceof DataView);\n}","tryCatchPattern":"try {\n  assert.typedArray(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // plain Array, ArrayBuffer, or DataView was passed instead of a typed array view\n  }\n  throw error;\n}","preventionTips":["Use ArrayBuffer.isView(value) && !(value instanceof DataView) — plain arrays and raw ArrayBuffers are not TypedArrays","Wrap raw buffers before the call: new Uint8Array(buffer)","In Node, remember Buffer is a Uint8Array subclass (passes), while ArrayBuffer and DataView do not"],"tags":["typescript","type-assertion","typed-array","binary-data","validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}