{"id":"1baf61f3d84eca0b","repo":"sindresorhus/is","slug":"expected-value-which-is-number-received-value-o","errorCode":null,"errorMessage":"Expected value which is `number`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `number`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1805,"sourceCode":"}\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)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('string with a number', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertObject(value: unknown, message?: string): asserts value is object {\n\tif (!isObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Object', value));\n\t}\n}\n\nexport function assertObservable(value: unknown, message?: string): asserts value is ObservableLike {\n\tif (!isObservable(value)) {","sourceCodeStart":1787,"sourceCodeEnd":1823,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1787-L1823","documentation":"Thrown by `assert.number()` in the `@sindresorhus/is` library when the given value is not of primitive type `number`. The assert family wraps the `is.*` predicates and throws a TypeError so the value can be safely narrowed via TypeScript's `asserts value is number`. The message interpolates `is(value)` to report the actual detected type of what was received.","triggerScenarios":"Calling `assert.number(value)` (or `assertNumber`) with anything whose typeof is not 'number' — strings like '42', BigInt, null, undefined, NaN is accepted since typeof NaN === 'number'. Common at API boundaries where JSON/query params arrive as strings.","commonSituations":"Parsing query strings, env vars, or form inputs where numbers arrive as strings; forgetting to call Number()/parseFloat before validation; a config file storing a number as a quoted string; upstream API changing a field from number to string.","solutions":["Convert the value first, e.g. `const n = Number(raw)` before `assert.number(n)`.","If the input is legitimately a numeric string, use `assert.numericString()` instead.","Log `is(value)` from the error message to identify what the caller actually passed and fix the producer.","If undefined is allowed, guard with `if (value !== undefined) assert.number(value)`."],"exampleFix":"// before\nconst port = process.env.PORT;\nassert.number(port); // throws: received 'string'\n// after\nconst port = Number(process.env.PORT);\nassert.number(port);","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'number' || Number.isNaN(value)) {\n  throw new TypeError(`Expected number, got ${typeof value}`);\n}","typeGuard":"function isNumber(value: unknown): value is number {\n  return typeof value === 'number' && !Number.isNaN(value);\n}","tryCatchPattern":"try {\n  ow(value, ow.number);\n} catch (error) {\n  if (error instanceof ArgumentError) {\n    // report invalid input to caller; do not substitute a default\n    throw new TypeError(`Invalid numeric input: ${error.message}`);\n  }\n  throw error;\n}","preventionTips":["Convert user/string input with Number() and check Number.isNaN before passing to the API","Remember typeof NaN === 'number' — decide explicitly whether NaN is acceptable","Type external data as unknown and narrow with a guard before calling the library","Avoid implicit coercion like +value or value * 1 hiding non-number inputs"],"tags":["type-check","assertion","runtime-validation","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}