{"id":"a522f7fad154ada5","repo":"sindresorhus/is","slug":"expected-value-which-is-int16array-received-val","errorCode":null,"errorMessage":"Expected value which is `Int16Array`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Int16Array`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1677,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('HTMLElement', value));\n\t}\n}\n\nexport function assertInfinite(value: unknown, message?: string): asserts value is number {\n\tif (!isInfinite(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('infinite number', value));\n\t}\n}\n\nexport function assertInRange(value: number, range: number | [number, number], message?: string): asserts value is number {\n\tif (!isInRange(value, range)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('in range', value));\n\t}\n}\n\nexport function assertInt16Array(value: unknown, message?: string): asserts value is Int16Array {\n\tif (!isInt16Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Int16Array', value));\n\t}\n}\n\nexport function assertInt32Array(value: unknown, message?: string): asserts value is Int32Array {\n\tif (!isInt32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Int32Array', value));\n\t}\n}\n\nexport function assertInt8Array(value: unknown, message?: string): asserts value is Int8Array {\n\tif (!isInt8Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Int8Array', value));\n\t}\n}\n\nexport function assertInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('integer', value));","sourceCodeStart":1659,"sourceCodeEnd":1695,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1659-L1695","documentation":"Thrown by `assertInt16Array()` when `isInt16Array()` fails — the value is not a genuine Int16Array instance. The check is by internal tag, so structurally similar values (plain arrays, other typed-array element types) are rejected.","triggerScenarios":"`is.assert.int16Array(value)` with a Uint16Array, Int8Array, plain `number[]`, ArrayBuffer, DataView, or Node Buffer.","commonSituations":"Audio/binary-protocol code confusing signed and unsigned 16-bit views (Int16Array vs Uint16Array — a very common mix-up for PCM audio); receiving raw ArrayBuffers from WebSocket/fetch and forgetting to wrap them; serialized data arriving as plain arrays.","solutions":["Wrap the source in the right view: `new Int16Array(arrayBuffer)` or `Int16Array.from(plainArray)`.","Double-check signedness — if the producer emits Uint16Array, either reinterpret the buffer (`new Int16Array(u16.buffer)`) or change the assertion to match the actual type.","For Node Buffers, create a view over the underlying memory: `new Int16Array(buf.buffer, buf.byteOffset, buf.byteLength / 2)`."],"exampleFix":"// before\nws.onmessage = e => { assertInt16Array(e.data); }; // ArrayBuffer\n// after\nws.onmessage = e => {\n  const samples = new Int16Array(e.data);\n  assertInt16Array(samples);\n};","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof Int16Array)) {\n  throw new TypeError(`Expected Int16Array, got ${typeof value}`);\n}","typeGuard":"function isInt16Array(value: unknown): value is Int16Array {\n  return value instanceof Int16Array;\n}","tryCatchPattern":"try {\n  assert.int16Array(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* convert with Int16Array.from or reject */ }\n  else throw error;\n}","preventionTips":["Convert explicitly with `Int16Array.from(arr)` or `new Int16Array(buffer)` — plain arrays and other typed-array kinds fail","Uint16Array and Int16Array are distinct despite identical element size; keep signedness straight in signatures","Use the library's cross-realm-safe `is.int16Array` when values may come from workers or iframes"],"tags":["typed-array","binary-data","type-assertion","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}