{"id":"a1d80ccb6d7e5d03","repo":"sindresorhus/is","slug":"expected-value-which-is-negative-number-receive","errorCode":null,"errorMessage":"Expected value which is `negative number`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `negative number`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1731,"sourceCode":"\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));\n\t}\n}\n\nexport function assertNodeStream(value: unknown, message?: string): asserts value is NodeStream {\n\tif (!isNodeStream(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Node.js Stream', value));\n\t}\n}\n\nexport function assertNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[], message?: string): asserts value is [Item, ...Item[]] {\n\tif (!isNonEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty array', value));\n\t}\n}\n\nexport function assertNonEmptyMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {\n\tif (!isNonEmptyMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty map', value));","sourceCodeStart":1713,"sourceCodeEnd":1749,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1713-L1749","documentation":"Thrown by `assertNegativeNumber()` (source/index.ts:1729) when the value fails `isNumber(value) && value < 0`. The value must be a number primitive strictly below zero; NaN, 0, -0, positive numbers, and numeric strings all fail (NaN fails both `isNumber` in this library and the `< 0` comparison).","triggerScenarios":"Calling `assertNegativeNumber()` with 0 or -0 (`-0 < 0` is false), a numeric string like '-2.5', NaN from a failed parse, or a positive number due to a sign error upstream.","commonSituations":"Boundary bugs where zero should count as valid; unparsed string input from forms/env/CLI; sign conventions flipping between systems (e.g. accounting credits vs debits, coordinate systems); `Math.abs` applied too early in a pipeline.","solutions":["Convert string input with `Number(raw)` before asserting and handle NaN explicitly.","If zero is acceptable, widen the contract (assert `value <= 0` yourself or use a non-positive check) instead of negative-number.","Audit the sign convention at the boundary where the value is produced — negate there if the source uses the opposite convention."],"exampleFix":"// before\nconst delta = form.get('delta'); // '-2.5' (string)\nassertNegativeNumber(delta); // throws\n// after\nconst delta = Number(form.get('delta'));\nassertNegativeNumber(delta);","handlingStrategy":"validation","validationCode":"if (typeof value !== 'number' || Number.isNaN(value) || value >= 0) {\n  throw new RangeError(`Expected negative number, got ${value}`);\n}","typeGuard":"const isNegativeNumber = (v: unknown): v is number => typeof v === 'number' && v < 0;","tryCatchPattern":null,"preventionTips":["NaN fails every comparison, so NaN is never negative — filter it out first with Number.isNaN","Subtraction results can be 0 or -0 in edge cases; both are non-negative for v < 0 checks","Numeric strings like '-5' are not numbers — convert with Number() and re-validate before asserting"],"tags":["number","validation","type-assertion"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}