sindresorhus/is · error · TypeError
Expected value which is `Float32Array`, received value of ty
Error message
Expected value which is `Float32Array`, received value of type `${is(value)}`. What it means
Thrown by `assertFloat32Array()` in the @sindresorhus/is type-assertion library when the checked value fails `isFloat32Array()`, which verifies the value's internal tag is `Float32Array` via `Object.prototype.toString`. Assert functions throw a TypeError so TypeScript can narrow the value type after the call; the message interpolates the detected type of the actual value.
Source
Thrown at source/index.ts:1622
throw new TypeError(message ?? typeErrorMessage('even integer', value));
}
}
export function assertFalsy(value: unknown, message?: string): asserts value is Falsy {
if (!isFalsy(value)) {
throw new TypeError(message ?? typeErrorMessage('falsy', value));
}
}
export function assertFiniteNumber(value: unknown, message?: string): asserts value is number {
if (!isFiniteNumber(value)) {
throw new TypeError(message ?? typeErrorMessage('finite number', value));
}
}
export function assertFloat32Array(value: unknown, message?: string): asserts value is Float32Array {
if (!isFloat32Array(value)) {
throw new TypeError(message ?? typeErrorMessage('Float32Array', value));
}
}
export function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array {
if (!isFloat64Array(value)) {
throw new TypeError(message ?? typeErrorMessage('Float64Array', value));
}
}
export function assertFormData(value: unknown, message?: string): asserts value is FormData {
if (!isFormData(value)) {
throw new TypeError(message ?? typeErrorMessage('FormData', value));
}
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export function assertFunction(value: unknown, message?: string): asserts value is Function {
if (!isFunction(value)) {View on GitHub ↗ (pinned to 7821031c66)
Solutions
- Convert the input before asserting: `new Float32Array(plainArrayOrBuffer)`.
- Check where the value originates (JSON.parse, message ports, WASM boundary) and construct the typed array at that boundary.
- If Float64Array is also acceptable, use `is.typedArray(value)` or a union check instead of the strict assertion.
Example fix
// before const data = JSON.parse(payload).samples; // number[] assertFloat32Array(data); // after const data = new Float32Array(JSON.parse(payload).samples); assertFloat32Array(data);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(value instanceof Float32Array)) {
throw new TypeError(`Expected Float32Array, got ${typeof value}`);
} Type guard
function isFloat32Array(value: unknown): value is Float32Array {
return value instanceof Float32Array;
} Try / catch
try {
assert.float32Array(value);
} catch (error) {
if (error instanceof TypeError) { /* convert or reject input */ }
else throw error;
} Prevention
- Check `value instanceof Float32Array` before calling assert.float32Array
- Don't confuse Float32Array with Float64Array or plain number[] — convert explicitly with `Float32Array.from(arr)`
- Remember typed arrays from other realms (iframes/workers) may fail instanceof; use `is.float32Array` from the library which handles cross-realm checks
When it happens
Trigger: Calling `is.assert.float32Array(value)` (or `assertFloat32Array(value)`) with anything other than a real Float32Array — e.g. a plain number array, Float64Array, ArrayBuffer, DataView, or a Node Buffer.
Common situations: WebGL/audio/ML code that receives a plain `number[]` from JSON or user input instead of a typed array; passing an ArrayBuffer without wrapping it in `new Float32Array(buffer)`; cross-realm typed arrays are fine (brand check), but structurally similar objects from serialization are not.
Related errors
- Expected value which is `Float64Array`, received value of ty
- Expected value which is `Uint16Array`, received value of typ
- Expected value which is `Uint32Array`, received value of typ
- Expected value which is `BigUint64Array`, received value of
- Expected value which is `empty map`, received value of type
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/a310bb87972c8234.json.
Report an issue: GitHub ↗.