{"id":"09d952fc403ea935","repo":"sindresorhus/is","slug":"expected-value-which-is-set-received-value-of-t","errorCode":null,"errorMessage":"Expected value which is `Set`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Set`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1884,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('PropertyKey', value));\n\t}\n}\n\nexport function assertRegExp(value: unknown, message?: string): asserts value is RegExp {\n\tif (!isRegExp(value)) {\n\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));","sourceCodeStart":1866,"sourceCodeEnd":1902,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1866-L1902","documentation":"Thrown by `assert.set()` (assertSet at source/index.ts:1882) when the value is not a native `Set` instance per `isSet`. The library distinguishes Sets from other collections by object-type tagging, so arrays, plain objects, Maps, and WeakSets all fail. The message reports the actual type via `is(value)`.","triggerScenarios":"Calling `assert.set(value)` with an array (`['a','b']`), a Map, a WeakSet, an object used as a set (`{a: true}`), or serialized data — Sets do not survive `JSON.parse`, arriving as `{}` or arrays.","commonSituations":"Data round-tripped through JSON (structuredClone preserves Sets, JSON does not); API layers that convert Sets to arrays; confusing `Set` with `WeakSet` or an array with unique values.","solutions":["Convert arrays to Sets before asserting: `new Set(array)`.","If the value crossed a JSON boundary, reconstruct the Set on deserialization since JSON.stringify turns Sets into `{}`.","If arrays are also acceptable, check `is.set(value) || is.array(value)` instead of asserting."],"exampleFix":"// before\nconst tags = JSON.parse(payload).tags; // arrives as array\nassert.set(tags);\n// after\nconst tags = new Set(JSON.parse(payload).tags);\nassert.set(tags);","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof Set)) {\n  throw new TypeError('Expected a Set');\n}","typeGuard":"function isSet(value: unknown): value is Set<unknown> {\n  return Object.prototype.toString.call(value) === '[object Set]';\n}","tryCatchPattern":"try {\n  assert.set(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // often an Array or plain object was passed — convert with new Set(iterable)\n  }\n  throw error;\n}","preventionTips":["Arrays are the most common wrong input — wrap with new Set(array) at the boundary","Remember JSON has no Set: deserialized data always needs explicit conversion","Type the parameter as Set<T> rather than Iterable<T> if the API truly requires a Set"],"tags":["typescript","type-assertion","collections","serialization"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}