sindresorhus/is · error · TypeError

Expected value which is `Uint32Array`, received value of typ

Error message

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

What it means

Thrown by `assertUint32Array()` in @sindresorhus/is when the value is not an actual Uint32Array instance (checked via its toStringTag). It guards code paths that require 32-bit unsigned element views, throwing a TypeError naming the actual received type.

Source

Thrown at source/index.ts:1932

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

export function assertUint8ClampedArray(value: unknown, message?: string): asserts value is Uint8ClampedArray {
	if (!isUint8ClampedArray(value)) {
		throw new TypeError(message ?? typeErrorMessage('Uint8ClampedArray', value));
	}
}

export function assertUndefined(value: unknown, message?: string): asserts value is undefined {
	if (!isUndefined(value)) {
		throw new TypeError(message ?? typeErrorMessage('undefined', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Wrap or convert: `new Uint32Array(buffer)` or `Uint32Array.from(values)`.
  2. Verify byte alignment — `new Uint32Array(buffer)` throws if the buffer length isn't a multiple of 4; slice/pad first.
  3. Use `assert.typedArray()` if the exact element type doesn't matter.

Example fix

// before
assert.uint32Array(nodeBuffer);
// after
assert.uint32Array(new Uint32Array(nodeBuffer.buffer, nodeBuffer.byteOffset, nodeBuffer.byteLength / 4));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!is.uint32Array(value)) {
  value = Uint32Array.from(value); // normalize or reject
}

Type guard

if (is.uint32Array(value)) {
  // value is Uint32Array here
}

Try / catch

try {
  assert.uint32Array(value);
} catch (error) {
  if (error instanceof TypeError) { /* handle non-Uint32Array input */ }
  throw error;
}

Prevention

When it happens

Trigger: `assert.uint32Array(value)` with a plain number array, a different TypedArray (Int32Array, Uint8Array), a DataView, or an ArrayBuffer.

Common situations: Hash/crypto/WebGL code expecting Uint32Array but handed a Buffer or Uint8Array; data deserialized from JSON or postMessage without reconstructing the typed array.

Related errors


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