sindresorhus/is · error · TypeError
Expected value which is `Uint8ClampedArray`, received value
Error message
Expected value which is `Uint8ClampedArray`, received value of type `${is(value)}`. What it means
Thrown by `assertUint8ClampedArray()` in @sindresorhus/is when the value is not a Uint8ClampedArray. This type is distinct from Uint8Array (clamping vs wrapping arithmetic) and the check is exact — a plain Uint8Array fails it.
Source
Thrown at source/index.ts:1944
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));
}
}
export function assertUrlInstance(value: unknown, message?: string): asserts value is URL {
if (!isUrlInstance(value)) {
throw new TypeError(message ?? typeErrorMessage('URL', value));
}
}
// eslint-disable-next-line unicorn/prevent-abbreviations
export function assertUrlSearchParams(value: unknown, message?: string): asserts value is URLSearchParams {
if (!isUrlSearchParams(value)) {View on GitHub ↗ (pinned to 7821031c66)
Solutions
- Construct the exact type: `new Uint8ClampedArray(length)` or `new Uint8ClampedArray(buffer)`.
- If you have ImageData, pass `imageData.data`, not the ImageData object.
- If clamping semantics don't matter to your code, relax the assertion to `assert.uint8Array` or `assert.typedArray`.
Example fix
// before assert.uint8ClampedArray(imageData); // after assert.uint8ClampedArray(imageData.data);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!is.uint8ClampedArray(value)) {
value = Uint8ClampedArray.from(value);
} Type guard
if (is.uint8ClampedArray(value)) {
// value is Uint8ClampedArray here
} Try / catch
try {
assert.uint8ClampedArray(value);
} catch (error) {
if (error instanceof TypeError) { /* handle wrong typed-array class */ }
throw error;
} Prevention
- Uint8Array and Uint8ClampedArray are different classes — check which one your API (e.g. ImageData.data) actually returns
- Guard with is.uint8ClampedArray() before asserting
- Convert explicitly with Uint8ClampedArray.from() when interoperating with plain Uint8Array pipelines
When it happens
Trigger: `assert.uint8ClampedArray(value)` with a Uint8Array, Buffer, plain array, or ArrayBuffer. Most commonly hit around canvas ImageData pipelines, since `ImageData.data` is the main real-world source of Uint8ClampedArray.
Common situations: Image-processing code that built pixel data with `new Uint8Array()` instead of `new Uint8ClampedArray()`; passing `imageData` (the object) instead of `imageData.data`.
Related errors
- Expected value which is `Float32Array`, received value of ty
- Expected value which is `Float64Array`, received value of ty
- Expected value which is `Int32Array`, received value of type
- Expected value which is `TypedArray`, received value of type
- Expected value which is `Uint16Array`, received value of typ
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/b4665b39b3273c56.json.
Report an issue: GitHub ↗.