{"id":"e0ca2cf887a21fe6","repo":"sindresorhus/is","slug":"expected-value-which-is-sharedarraybuffer-recei","errorCode":null,"errorMessage":"Expected value which is `SharedArrayBuffer`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `SharedArrayBuffer`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1890,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('RegExp', value));\n\t}\n}\n\nexport function assertSafeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isSafeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('safe integer', value));\n\t}\n}\n\nexport function assertSet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {\n\tif (!isSet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Set', value));\n\t}\n}\n\nexport function assertSharedArrayBuffer(value: unknown, message?: string): asserts value is SharedArrayBuffer {\n\tif (!isSharedArrayBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('SharedArrayBuffer', value));\n\t}\n}\n\nexport function assertString(value: unknown, message?: string): asserts value is string {\n\tif (!isString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('string', value));\n\t}\n}\n\nexport function assertSymbol(value: unknown, message?: string): asserts value is symbol {\n\tif (!isSymbol(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('symbol', value));\n\t}\n}\n\nexport function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T {\n\tif (!isTruthy(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('truthy', value));","sourceCodeStart":1872,"sourceCodeEnd":1908,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1872-L1908","documentation":"Thrown by `assert.sharedArrayBuffer()` (assertSharedArrayBuffer at source/index.ts:1888) when the value is not a `SharedArrayBuffer` instance. Regular `ArrayBuffer`, typed arrays, and DataViews all fail — the two buffer types are distinct classes. This assertion also fails when `SharedArrayBuffer` itself is unavailable in the environment.","triggerScenarios":"Calling `assert.sharedArrayBuffer(value)` with a plain `ArrayBuffer`, a `Uint8Array` (a view, not a buffer), or in browsers where SharedArrayBuffer is disabled because the page is not cross-origin isolated (missing COOP/COEP headers).","commonSituations":"Browsers hide SharedArrayBuffer unless the page sends `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (post-Spectre mitigation), so worker code that works in Node fails in the browser; passing a typed array's `.buffer` which is an ArrayBuffer unless explicitly allocated shared.","solutions":["Allocate the buffer as shared: `new SharedArrayBuffer(size)` instead of `new ArrayBuffer(size)`.","In browsers, enable cross-origin isolation with COOP/COEP headers so SharedArrayBuffer exists.","If a value is a typed array, pass `view.buffer` only when the view was created over a SharedArrayBuffer; otherwise use `assert.arrayBuffer()`."],"exampleFix":"// before\nconst buf = new ArrayBuffer(1024);\nassert.sharedArrayBuffer(buf);\n// after\nconst buf = new SharedArrayBuffer(1024);\nassert.sharedArrayBuffer(buf);","handlingStrategy":"validation","validationCode":"if (typeof SharedArrayBuffer === 'undefined') {\n  throw new Error('SharedArrayBuffer unavailable (needs cross-origin isolation)');\n}\nif (!(value instanceof SharedArrayBuffer)) {\n  throw new TypeError('Expected a SharedArrayBuffer');\n}","typeGuard":"function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer {\n  return typeof SharedArrayBuffer !== 'undefined' && Object.prototype.toString.call(value) === '[object SharedArrayBuffer]';\n}","tryCatchPattern":"try {\n  assert.sharedArrayBuffer(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // likely a plain ArrayBuffer, or SAB is disabled in this environment\n  }\n  throw error;\n}","preventionTips":["Check environment support first — browsers require COOP/COEP headers for SharedArrayBuffer to exist","Don't confuse ArrayBuffer with SharedArrayBuffer; they are distinct types and postMessage/transfer semantics differ","Guard worker-message handlers, since buffers arriving via postMessage may be either kind"],"tags":["typescript","type-assertion","shared-array-buffer","web-workers","cross-origin-isolation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}