{"id":"90645189f7426acf","repo":"sindresorhus/is","slug":"expected-value-which-is-undefined-received-valu","errorCode":null,"errorMessage":"Expected value which is `undefined`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `undefined`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1950,"sourceCode":"\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));\n\t}\n}\n\nexport function assertUndefined(value: unknown, message?: string): asserts value is undefined {\n\tif (!isUndefined(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('undefined', value));\n\t}\n}\n\nexport function assertUrlInstance(value: unknown, message?: string): asserts value is URL {\n\tif (!isUrlInstance(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('URL', value));\n\t}\n}\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport function assertUrlSearchParams(value: unknown, message?: string): asserts value is URLSearchParams {\n\tif (!isUrlSearchParams(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('URLSearchParams', value));\n\t}\n}\n\nexport function assertUrlString(value: unknown, message?: string): asserts value is UrlString {\n\tif (!isUrlString(value)) {","sourceCodeStart":1932,"sourceCodeEnd":1968,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1932-L1968","documentation":"Thrown by `assertUndefined()` in @sindresorhus/is when the value is anything other than literal `undefined`. It's a strict `value === undefined` check — `null`, empty string, 0, and false all fail.","triggerScenarios":"`assert.undefined(value)` receiving `null` or any defined value — often used to assert an option/slot has not been set yet, or in exhaustiveness checks.","commonSituations":"APIs that return `null` where the code expected `undefined` (e.g. DOM getters, JSON round-trips which turn undefined into missing/null); asserting a map slot is empty when a falsy-but-defined default was stored.","solutions":["If null should also pass, use `assert.nullOrUndefined(value)` instead.","Trace where the value gets defined — the assertion is telling you initialization/reset logic ran in the wrong order.","Normalize null to undefined at the boundary: `value ?? undefined` only converts nullish, so explicitly map `value === null ? undefined : value` if needed."],"exampleFix":"// before\nassert.undefined(map.get(key)); // fails: stored null\n// after\nassert.nullOrUndefined(map.get(key));","handlingStrategy":"type-guard","validationCode":"if (value !== undefined) {\n  // clear or reject the value before asserting\n}","typeGuard":"if (is.undefined(value)) {\n  // value is undefined here\n}","tryCatchPattern":"try {\n  assert.undefined(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* value was unexpectedly set */ }\n  throw error;\n}","preventionTips":["Remember null is NOT undefined — use is.nullOrUndefined() if either is acceptable","Use assert.undefined() only where a value being set indicates a logic error","Prefer a plain value === undefined check when you just need branching, reserving the assert for invariants"],"tags":["typescript","type-assertion","null-vs-undefined"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}