{"id":"f1048bf248148e2c","repo":"sindresorhus/is","slug":"expected-value-which-is-null-received-value-of","errorCode":null,"errorMessage":"Expected value which is `null`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `null`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1792,"sourceCode":"\t}\n}\n\nexport function assertNonNegativeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isNonNegativeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-negative integer', value));\n\t}\n}\n\nexport function assertNonNegativeNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNonNegativeNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-negative number', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertNull(value: unknown, message?: string): asserts value is null {\n\tif (!isNull(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('null', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertNullOrUndefined(value: unknown, message?: string): asserts value is null | undefined {\n\tif (!isNullOrUndefined(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('null or undefined', value));\n\t}\n}\n\nexport function assertNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('number', value));\n\t}\n}\n\nexport function assertNumericString(value: unknown, message?: string): asserts value is `${number}` {\n\tif (!isNumericString(value)) {","sourceCodeStart":1774,"sourceCodeEnd":1810,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1774-L1810","documentation":"Thrown by `assertNull()` (source/index.ts:1790) when the value is anything other than exactly `null`. This is a strict identity check — `undefined`, `0`, `''`, and `false` all fail. It's typically used to assert that something has NOT been set or was explicitly cleared.","triggerScenarios":"Calling `assert.null_(value)` / `assertNull(value)` with `undefined` (the most common confusion — e.g. a missing object property or uninitialized variable), or with any value when the code expected a cleared/absent state.","commonSituations":"APIs that use `undefined` for 'never set' but `null` for 'explicitly cleared' — asserting null on a property that was simply never assigned; DOM/library methods returning `undefined` where `null` was expected; state that should have been reset before reuse but wasn't.","solutions":["If either absent value is acceptable, use `assert.nullOrUndefined(value)` instead.","Normalize at the boundary: `value ?? null` to convert `undefined` to `null` when that's the intended semantic.","If the assertion is guarding 'this slot must be empty before reuse', find why the previous consumer didn't reset it to null."],"exampleFix":"// before\nassert.null_(cache.entry); // entry was never assigned → undefined → throws\n// after\nassert.nullOrUndefined(cache.entry); // accept both absent states","handlingStrategy":"type-guard","validationCode":"if (value === null) {\n  assert.null_(value);\n}","typeGuard":"function isNull(v: unknown): v is null {\n  return v === null;\n}","tryCatchPattern":"try {\n  assert.null_(result);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // result is undefined or a real value, not null — check what produced it\n  }\n  throw error;\n}","preventionTips":["Compare with === null; this assert rejects undefined, so the two are not interchangeable here","Know your API's convention: some return null for 'not found' and undefined for 'not set' — assert the one it actually returns","Use is.null_(value) in conditionals; note the trailing underscore since null is a reserved word"],"tags":["assertion","type-check","null","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}