{"id":"3180b09d1b65a585","repo":"sindresorhus/is","slug":"expected-value-which-is-finite-number-received","errorCode":null,"errorMessage":"Expected value which is `finite number`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `finite number`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1616,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Error', value));\n\t}\n}\n\nexport function assertEvenInteger(value: number, message?: string): asserts value is number {\n\tif (!isEvenInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('even integer', value));\n\t}\n}\n\nexport function assertFalsy(value: unknown, message?: string): asserts value is Falsy {\n\tif (!isFalsy(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('falsy', value));\n\t}\n}\n\nexport function assertFiniteNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isFiniteNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('finite number', value));\n\t}\n}\n\nexport function assertFloat32Array(value: unknown, message?: string): asserts value is Float32Array {\n\tif (!isFloat32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Float32Array', value));\n\t}\n}\n\nexport function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array {\n\tif (!isFloat64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Float64Array', value));\n\t}\n}\n\nexport function assertFormData(value: unknown, message?: string): asserts value is FormData {\n\tif (!isFormData(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('FormData', value));","sourceCodeStart":1598,"sourceCodeEnd":1634,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1598-L1634","documentation":"Thrown by `assertFiniteNumber` (source/index.ts:1614) when the value is not a finite number — i.e. it fails `Number.isFinite`. Non-numbers, `NaN`, `Infinity`, and `-Infinity` all fail. This guards arithmetic pipelines against silent NaN/Infinity propagation, which the library's fail-fast philosophy treats as an immediate error.","triggerScenarios":"Calling `assert.finiteNumber(value)` with `NaN` (e.g. from `parseInt('abc')` or `0/0`), `Infinity` (from division by zero or overflow), a numeric string like `'42'`, null, or undefined.","commonSituations":"Parsing user/config input with `parseFloat`/`Number()` and getting NaN from malformed strings; division by zero in metrics or ratio calculations; JSON payloads carrying numbers as strings; missing object properties yielding undefined in arithmetic.","solutions":["Trace the NaN/Infinity to its source — usually a failed parse or division by zero — and validate inputs there","Convert numeric strings explicitly with `Number(value)` and check the parse succeeded before asserting","Guard divisions: check the divisor is non-zero before computing","If Infinity is a legitimate value in your domain, use `assert.number(value)` instead"],"exampleFix":"// before\nconst rate = Number(input);\nassert.finiteNumber(rate); // throws if input was 'abc'\n// after\nconst rate = Number(input);\nif (Number.isNaN(rate)) throw new Error(`Invalid rate input: ${input}`);\nassert.finiteNumber(rate);","handlingStrategy":"validation","validationCode":"if (Number.isFinite(value)) {\n  assert.finiteNumber(value);\n}","typeGuard":"function isFiniteNumber(value: unknown): value is number {\n  return typeof value === 'number' && Number.isFinite(value);\n}","tryCatchPattern":"try {\n  assert.finiteNumber(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // NaN, Infinity, -Infinity, or a non-number — often from division by zero or failed parse\n  } else throw error;\n}","preventionTips":["Use Number.isFinite (not the global isFinite, which coerces strings) as the pre-check","Guard arithmetic that can produce Infinity (division by zero) or NaN (0/0, failed parseFloat) before passing results downstream","Validate numeric inputs at the trust boundary so infinities never propagate deep into the code"],"tags":["type-assertion","runtime-validation","number","nan","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}