{"id":"b4665b39b3273c56","repo":"sindresorhus/is","slug":"expected-value-which-is-uint8clampedarray-recei","errorCode":null,"errorMessage":"Expected value which is `Uint8ClampedArray`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Uint8ClampedArray`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1944,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Uint16Array', value));\n\t}\n}\n\nexport function assertUint32Array(value: unknown, message?: string): asserts value is Uint32Array {\n\tif (!isUint32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint32Array', value));\n\t}\n}\n\nexport function assertUint8Array(value: unknown, message?: string): asserts value is Uint8Array {\n\tif (!isUint8Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint8Array', value));\n\t}\n}\n\nexport function assertUint8ClampedArray(value: unknown, message?: string): asserts value is Uint8ClampedArray {\n\tif (!isUint8ClampedArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint8ClampedArray', value));\n\t}\n}\n\nexport function assertUndefined(value: unknown, message?: string): asserts value is undefined {\n\tif (!isUndefined(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('undefined', value));\n\t}\n}\n\nexport function assertUrlInstance(value: unknown, message?: string): asserts value is URL {\n\tif (!isUrlInstance(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('URL', value));\n\t}\n}\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport function assertUrlSearchParams(value: unknown, message?: string): asserts value is URLSearchParams {\n\tif (!isUrlSearchParams(value)) {","sourceCodeStart":1926,"sourceCodeEnd":1962,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1926-L1962","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Image-processing code that built pixel data with `new Uint8Array()` instead of `new Uint8ClampedArray()`; passing `imageData` (the object) instead of `imageData.data`.","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`."],"exampleFix":"// before\nassert.uint8ClampedArray(imageData);\n// after\nassert.uint8ClampedArray(imageData.data);","handlingStrategy":"type-guard","validationCode":"if (!is.uint8ClampedArray(value)) {\n  value = Uint8ClampedArray.from(value);\n}","typeGuard":"if (is.uint8ClampedArray(value)) {\n  // value is Uint8ClampedArray here\n}","tryCatchPattern":"try {\n  assert.uint8ClampedArray(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* handle wrong typed-array class */ }\n  throw error;\n}","preventionTips":["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"],"tags":["typescript","type-assertion","typed-array","canvas"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}