{"id":"51553a44bf8aba44","repo":"sindresorhus/is","slug":"expected-value-which-is-positive-number-receive","errorCode":null,"errorMessage":"Expected value which is `positive number`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `positive number`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1848,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('odd integer', value));\n\t}\n}\n\nexport function assertPlainObject<Value = unknown>(value: unknown, message?: string): asserts value is Record<PropertyKey, Value> {\n\tif (!isPlainObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('plain object', value));\n\t}\n}\n\nexport function assertPositiveInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isPositiveInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('positive integer', value));\n\t}\n}\n\nexport function assertPositiveNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isPositiveNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('positive number', value));\n\t}\n}\n\nexport function assertPrimitive(value: unknown, message?: string): asserts value is Primitive {\n\tif (!isPrimitive(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('primitive', value));\n\t}\n}\n\nexport function assertPromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {\n\tif (!isPromise(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Promise', value));\n\t}\n}\n\nexport function assertPropertyKey(value: unknown, message?: string): asserts value is PropertyKey {\n\tif (!isPropertyKey(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('PropertyKey', value));","sourceCodeStart":1830,"sourceCodeEnd":1866,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1830-L1866","documentation":"Thrown by `assert.positiveNumber()` when the value is not a number strictly greater than zero. Unlike `positiveInteger`, fractional values are allowed, but 0, negatives, NaN, and non-numbers fail. Guards quantities like durations, rates, prices, and dimensions that must be positive.","triggerScenarios":"Calling `assert.positiveNumber(value)` with 0, a negative number, NaN (e.g. from `Number('abc')`), a numeric string, null, or undefined. Note that `Infinity` is a positive number and passes.","commonSituations":"Timeout or interval values defaulting to 0; price/quantity computed from a subtraction going negative; NaN propagating from a failed string-to-number conversion in config or user input; unit mixups producing 0 after truncation.","solutions":["Check whether 0 should be allowed in your domain; if so use `assert.number()` with an explicit `>= 0` check.","Guard against NaN at the parse site: `const n = Number(raw); if (Number.isNaN(n)) throw new Error('invalid <field>')`.","Convert string inputs to numbers before asserting.","Add a domain-specific minimum/default before the assert instead of letting 0 reach it."],"exampleFix":"// before\nconst timeout = Number(config.timeout); // config.timeout = 'fast' → NaN\nassert.positiveNumber(timeout);\n// after\nconst parsed = Number(config.timeout);\nconst timeout = Number.isFinite(parsed) && parsed > 0 ? parsed : 5000;\nassert.positiveNumber(timeout);","handlingStrategy":"validation","validationCode":"if (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {\n  throw new RangeError(`Expected positive number, got ${value}`);\n}","typeGuard":"function isPositiveNumber(value: unknown): value is number {\n  return typeof value === 'number' && !Number.isNaN(value) && value > 0;\n}","tryCatchPattern":"try {\n  ow(value, ow.number.positive);\n} catch (error) {\n  if (error instanceof ArgumentError) {\n    throw new RangeError(`Value must be greater than zero: ${error.message}`);\n  }\n  throw error;\n}","preventionTips":["Zero is not positive — decide whether your use case needs > 0 or >= 0 and check accordingly","NaN fails every comparison; screen it out explicitly after arithmetic that can divide by zero","Subtraction of timestamps or measurements can go negative — validate the difference, not the inputs","Beware -0: it equals 0 but can appear from negative arithmetic"],"tags":["type-check","assertion","number-validation","input-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}