{"id":"ab739176b6de6099","repo":"sindresorhus/is","slug":"expected-value-which-is-uint16array-received-va","errorCode":null,"errorMessage":"Expected value which is `Uint16Array`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Uint16Array`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1926,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('truthy', value));\n\t}\n}\n\nexport function assertTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string): asserts value is ResolveTypesOfTypeGuardsTuple<T> {\n\tif (!isTupleLike(value, guards)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('tuple-like', value));\n\t}\n}\n\nexport function assertTypedArray(value: unknown, message?: string): asserts value is TypedArray {\n\tif (!isTypedArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('TypedArray', value));\n\t}\n}\n\nexport function assertUint16Array(value: unknown, message?: string): asserts value is Uint16Array {\n\tif (!isUint16Array(value)) {\n\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));","sourceCodeStart":1908,"sourceCodeEnd":1944,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1908-L1944","documentation":"Thrown by `assertUint16Array()` in @sindresorhus/is when the value's toStringTag is not `Uint16Array`. The assert wraps `isUint16Array()` and throws a TypeError with the detected runtime type interpolated so failures fail fast instead of propagating a wrong type.","triggerScenarios":"Calling `assert.uint16Array(value)` / `assertUint16Array(value)` with anything other than a real Uint16Array — e.g. a plain Array of numbers, a Uint8Array, an ArrayBuffer, or a Node Buffer view of a different element size.","commonSituations":"Passing a raw ArrayBuffer instead of a view over it; decoding binary protocol data and forgetting `new Uint16Array(buffer)`; receiving JSON-serialized data where the typed array became a plain array or `{\"0\":..}` object.","solutions":["Construct the correct view: `new Uint16Array(buffer)` or `Uint16Array.from(array)` before asserting.","Check the producer of the value — typed arrays don't survive JSON serialization; use structuredClone or re-wrap on receipt.","If any typed array is acceptable, use `assert.typedArray()` instead."],"exampleFix":"// before\nassert.uint16Array(buffer); // buffer is ArrayBuffer\n// after\nassert.uint16Array(new Uint16Array(buffer));","handlingStrategy":"type-guard","validationCode":"if (!is.uint16Array(value)) {\n  value = new Uint16Array(value); // or reject the input\n}","typeGuard":"if (is.uint16Array(value)) {\n  assert.uint16Array(value); // never throws\n}","tryCatchPattern":"try {\n  assert.uint16Array(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* report bad input */ }\n  throw error;\n}","preventionTips":["Use is.uint16Array() to check before calling assert.uint16Array()","Remember each TypedArray class is distinct — a Uint8Array will not pass a Uint16Array check","Type binary buffers explicitly at API boundaries instead of accepting ArrayBufferView"],"tags":["typescript","type-assertion","typed-array","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}