{"id":"e1312ddba59e66e5","repo":"sindresorhus/is","slug":"expected-value-which-is-nan-received-value-of-t","errorCode":null,"errorMessage":"Expected value which is `NaN`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `NaN`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"warning","filePath":"source/index.ts","lineNumber":1713,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('integer', value));\n\t}\n}\n\nexport function assertIterable<T = unknown>(value: unknown, message?: string): asserts value is Iterable<T> {\n\tif (!isIterable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Iterable', value));\n\t}\n}\n\nexport function assertMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {\n\tif (!isMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Map', value));\n\t}\n}\n\nexport function assertNan(value: unknown, message?: string): asserts value is number {\n\tif (!isNan(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('NaN', value));\n\t}\n}\n\nexport function assertNativePromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {\n\tif (!isNativePromise(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('native Promise', value));\n\t}\n}\n\nexport function assertNegativeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isNegativeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('negative integer', value));\n\t}\n}\n\nexport function assertNegativeNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNegativeNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('negative number', value));","sourceCodeStart":1695,"sourceCodeEnd":1731,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1695-L1731","documentation":"Thrown by `assertNan()` (source/index.ts:1711) when `Number.isNaN(value)` is false — this assert requires the value to literally BE NaN, the opposite of the usual 'not NaN' check. It exists for code paths (tests, sentinel handling) that expect a NaN result.","triggerScenarios":"Calling `assertNan()` with any valid number, a non-number (strings never pass — `Number.isNaN` does not coerce, so even 'foo' fails), null, or undefined.","commonSituations":"The most common hit is a semantic mix-up: developers call `assertNan(value)` intending to assert the value is a number that is NOT NaN. Also tests asserting a computation produced NaN when it actually produced Infinity or 0, and expecting the coercing global `isNaN('foo') === true` behavior — `Number.isNaN('foo')` is false.","solutions":["If you meant 'must be a real, usable number', use `assertNumber()` (which in this library excludes NaN) instead of `assertNan()`.","If you genuinely expect NaN, check why the computation produced a real value instead (e.g. 1/0 gives Infinity, not NaN).","Remember `assertNan` uses non-coercing `Number.isNaN` — pass the numeric result, not a raw string."],"exampleFix":"// before — intended to validate a usable number\nassertNan(input); // throws for every valid number!\n// after\nassertNumber(input); // excludes NaN in this library","handlingStrategy":"validation","validationCode":"if (!Number.isNaN(value)) {\n  // value is a real number or non-number — this assert expects literally NaN\n}","typeGuard":"const isNaNValue = (v: unknown): v is number => typeof v === 'number' && Number.isNaN(v);","tryCatchPattern":null,"preventionTips":["assert.nan expects the value to BE NaN — only use it when asserting a computation intentionally produced NaN","Use Number.isNaN, not global isNaN, which coerces and returns true for non-numeric strings","NaN !== NaN, so never compare with ===; Number.isNaN or Object.is(v, NaN) are the correct checks"],"tags":["number","nan","type-assertion"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}