sindresorhus/is · error · TypeError

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

Error message

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

What it means

Thrown by `assertInt8Array()` (source/index.ts:1687) when `isInt8Array()` fails; that predicate requires the value's object type tag to be exactly 'Int8Array'. It exists so code consuming signed 8-bit binary data fails immediately with the received type named rather than misbehaving later.

Source

Thrown at source/index.ts:1689

		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));
	}
}

export function assertMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {
	if (!isMap(value)) {
		throw new TypeError(message ?? typeErrorMessage('Map', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Convert without copying: `new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)` for a Buffer/Uint8Array view.
  2. Construct from a plain array or ArrayBuffer: `new Int8Array(data)`.
  3. If unsigned bytes are actually what you handle, assert `assertUint8Array()` or the generic `assertTypedArray()` instead.

Example fix

// before
const buf = await fs.promises.readFile(path);
assertInt8Array(buf); // throws — Buffer is a Uint8Array
// after
const bytes = new Int8Array(buf.buffer, buf.byteOffset, buf.byteLength);
assertInt8Array(bytes);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value instanceof Int8Array)) {
  throw new TypeError('Expected Int8Array, got ' + (value?.constructor?.name ?? typeof value));
}

Type guard

const isInt8Array = (v: unknown): v is Int8Array => v instanceof Int8Array;

Prevention

When it happens

Trigger: Calling `assertInt8Array(value)` with a Uint8Array, Node.js Buffer (which is a Uint8Array subclass, tag 'Uint8Array'), plain array, ArrayBuffer, or DataView — only a genuine Int8Array passes.

Common situations: Node.js Buffers are the classic trap: `fs.readFile` and network APIs return Buffer/Uint8Array, which fails the Int8Array check even though the bytes are compatible. Also plain arrays from JSON payloads.

Related errors


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