{"id":"44698510991c06d6","repo":"sindresorhus/is","slug":"expected-value-which-is-dataview-received-value","errorCode":null,"errorMessage":"Expected value which is `DataView`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `DataView`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1538,"sourceCode":"\n/**\nNote: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)\n*/\nexport function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer {\n\tif (!isBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Buffer', value));\n\t}\n}\n\nexport function assertClass<T>(value: unknown, message?: string): asserts value is Class<T> {\n\tif (!isClass(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Class', value));\n\t}\n}\n\nexport function assertDataView(value: unknown, message?: string): asserts value is DataView {\n\tif (!isDataView(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('DataView', value));\n\t}\n}\n\nexport function assertDate(value: unknown, message?: string): asserts value is Date {\n\tif (!isDate(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Date', value));\n\t}\n}\n\nexport function assertDirectInstanceOf<T>(instance: unknown, class_: Class<T>, message?: string): asserts instance is T {\n\tif (!isDirectInstanceOf(instance, class_)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('T', instance));\n\t}\n}\n\nexport function assertEmptyArray(value: unknown, message?: string): asserts value is never[] {\n\tif (!isEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty array', value));","sourceCodeStart":1520,"sourceCodeEnd":1556,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1520-L1556","documentation":"Thrown by `assertDataView()` when the value fails `isDataView` (object type 'DataView'). It ensures code can safely call DataView accessor methods (`getUint32`, `setFloat64`, etc.) for endianness-controlled binary reads.","triggerScenarios":"Calling `assert.dataView(value)` with a raw ArrayBuffer, a Uint8Array/other typed-array view, a Node Buffer, or a serialized representation of a DataView.","commonSituations":"Binary protocol parsers that receive `ArrayBuffer` from WebSocket/fetch and forget to wrap it; mixing typed-array views and DataView in the same parsing code; structured-clone/postMessage boundaries delivering the underlying buffer rather than the view.","solutions":["Wrap the buffer before asserting: `new DataView(arrayBuffer)` or `new DataView(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength)`.","If you only need byte access without endianness control, assert `uint8Array` instead.","Trace the producer to confirm which binary representation it emits and normalize at the boundary."],"exampleFix":"// before\nassert.dataView(message.data);\n// after\nassert.dataView(new DataView(message.data));","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof DataView)) {\n  value = new DataView(value instanceof ArrayBuffer ? value : value.buffer);\n}","typeGuard":"function isDataView(value: unknown): value is DataView {\n  return value instanceof DataView;\n}","tryCatchPattern":"try {\n  assert.dataView(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // got an ArrayBuffer or typed array — wrap: new DataView(buffer, byteOffset, byteLength)\n  } else throw error;\n}","preventionTips":["DataView, ArrayBuffer, and typed arrays are distinct types — wrap buffers in new DataView(buffer) at the call site","When wrapping a typed array's buffer, pass its byteOffset and byteLength to avoid viewing the whole underlying buffer","Cross-realm DataViews fail instanceof — normalize by re-wrapping the buffer in the local realm"],"tags":["type-assertion","dataview","binary-data","typed-array"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}