sindresorhus/is · error · TypeError
Expected value which is `TypedArray`, received value of type
Error message
Expected value which is `TypedArray`, received value of type `${is(value)}`. What it means
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.
Source
Thrown at source/index.ts:1920
throw new TypeError(message ?? typeErrorMessage('symbol', value));
}
}
export function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T {
if (!isTruthy(value)) {
throw new TypeError(message ?? typeErrorMessage('truthy', value));
}
}
export function assertTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string): asserts value is ResolveTypesOfTypeGuardsTuple<T> {
if (!isTupleLike(value, guards)) {
throw new TypeError(message ?? typeErrorMessage('tuple-like', value));
}
}
export function assertTypedArray(value: unknown, message?: string): asserts value is TypedArray {
if (!isTypedArray(value)) {
throw new TypeError(message ?? typeErrorMessage('TypedArray', value));
}
}
export function assertUint16Array(value: unknown, message?: string): asserts value is Uint16Array {
if (!isUint16Array(value)) {
throw new TypeError(message ?? typeErrorMessage('Uint16Array', value));
}
}
export function assertUint32Array(value: unknown, message?: string): asserts value is Uint32Array {
if (!isUint32Array(value)) {
throw new TypeError(message ?? typeErrorMessage('Uint32Array', value));
}
}
export function assertUint8Array(value: unknown, message?: string): asserts value is Uint8Array {
if (!isUint8Array(value)) {
throw new TypeError(message ?? typeErrorMessage('Uint8Array', value));View on GitHub ↗ (pinned to 7821031c66)
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.
Example fix
// before const data = await response.arrayBuffer(); assert.typedArray(data); // after const data = new Uint8Array(await response.arrayBuffer()); assert.typedArray(data);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!ArrayBuffer.isView(value) || value instanceof DataView) {
throw new TypeError('Expected a TypedArray');
} Type guard
function isTypedArray(value: unknown): value is Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array {
return ArrayBuffer.isView(value) && !(value instanceof DataView);
} Try / catch
try {
assert.typedArray(value);
} catch (error) {
if (error instanceof TypeError) {
// plain Array, ArrayBuffer, or DataView was passed instead of a typed array view
}
throw error;
} Prevention
- 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
When it happens
Trigger: 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:[...]}`).
Common situations: 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.
Related errors
- Expected value which is `Uint8Array`, received value of type
- Expected value which is `BigInt64Array`, received value of t
- Expected value which is `DataView`, received value of type `
- Expected value which is `Float32Array`, received value of ty
- Expected value which is `Float64Array`, received value of ty
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/89002d89407f0d3f.json.
Report an issue: GitHub ↗.