sindresorhus/is · error · TypeError

Expected value which is `Int32Array`, received value of type

Error message

Expected value which is `Int32Array`, received value of type `${is(value)}`.

What it means

Thrown by `assertInt32Array()` (source/index.ts:1681) when the value fails `isInt32Array()`, which checks the internal object type tag via `getObjectType(value) === 'Int32Array'`. The library uses assert functions to fail fast with a TypeError that names the actual received type instead of letting bad data propagate.

Source

Thrown at source/index.ts:1683

		throw new TypeError(message ?? typeErrorMessage('infinite number', value));
	}
}

export function assertInRange(value: number, range: number | [number, number], message?: string): asserts value is number {
	if (!isInRange(value, range)) {
		throw new TypeError(message ?? typeErrorMessage('in range', value));
	}
}

export function assertInt16Array(value: unknown, message?: string): asserts value is Int16Array {
	if (!isInt16Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Int16Array', value));
	}
}

export function assertInt32Array(value: unknown, message?: string): asserts value is Int32Array {
	if (!isInt32Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Int32Array', value));
	}
}

export function assertInt8Array(value: unknown, message?: string): asserts value is Int8Array {
	if (!isInt8Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Int8Array', value));
	}
}

export function assertInteger(value: unknown, message?: string): asserts value is number {
	if (!isInteger(value)) {
		throw new TypeError(message ?? typeErrorMessage('integer', value));
	}
}

export function assertIterable<T = unknown>(value: unknown, message?: string): asserts value is Iterable<T> {
	if (!isIterable(value)) {
		throw new TypeError(message ?? typeErrorMessage('Iterable', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Wrap the data before asserting: `new Int32Array(plainArray)` or `new Int32Array(arrayBuffer)`.
  2. If the value comes from JSON or structured serialization, reconstruct the typed array after parsing.
  3. If any typed array is acceptable, use `assertTypedArray()` instead of the Int32Array-specific assert.

Example fix

// before
const data = [1, 2, 3];
assertInt32Array(data); // throws
// after
const data = new Int32Array([1, 2, 3]);
assertInt32Array(data);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value instanceof Int32Array)) {
  value = new Int32Array(value); // or handle explicitly
}

Type guard

const isInt32Array = (v: unknown): v is Int32Array => v instanceof Int32Array;

Prevention

When it happens

Trigger: Calling `assertInt32Array(value)` with anything that isn't a real Int32Array: a plain Array of numbers, an ArrayBuffer, a Buffer/Uint8Array, an Int32Array from another mechanism that lost its type tag, or null/undefined.

Common situations: Passing a plain `[1,2,3]` array where binary APIs (WebGL, WASM, audio) need typed arrays; deserializing JSON (typed arrays become plain objects/arrays); passing an ArrayBuffer without wrapping it; cross-realm typed arrays are handled since the check uses the toString tag, so this is rarely a realm issue.

Related errors


AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31). Data as JSON: /data/errors/6f62416b1376af9e.json. Report an issue: GitHub ↗.