{"id":"e1c71b12c9ded338","repo":"sindresorhus/is","slug":"expected-value-which-is-infinite-number-receive","errorCode":null,"errorMessage":"Expected value which is `infinite number`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `infinite number`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1665,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Generator', value));\n\t}\n}\n\nexport function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction {\n\tif (!isGeneratorFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('GeneratorFunction', value));\n\t}\n}\n\nexport function assertHtmlElement(value: unknown, message?: string): asserts value is HTMLElement {\n\tif (!isHtmlElement(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('HTMLElement', value));\n\t}\n}\n\nexport function assertInfinite(value: unknown, message?: string): asserts value is number {\n\tif (!isInfinite(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('infinite number', value));\n\t}\n}\n\nexport function assertInRange(value: number, range: number | [number, number], message?: string): asserts value is number {\n\tif (!isInRange(value, range)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('in range', value));\n\t}\n}\n\nexport function assertInt16Array(value: unknown, message?: string): asserts value is Int16Array {\n\tif (!isInt16Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Int16Array', value));\n\t}\n}\n\nexport function assertInt32Array(value: unknown, message?: string): asserts value is Int32Array {\n\tif (!isInt32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Int32Array', value));","sourceCodeStart":1647,"sourceCodeEnd":1683,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1647-L1683","documentation":"Thrown by `assertInfinite()` when `isInfinite()` fails — the value is not exactly `Infinity` or `-Infinity`. This is the inverse of the far more common finite-number check, asserting that a number is specifically infinite.","triggerScenarios":"`is.assert.infinite(value)` with any finite number, `NaN`, a numeric string like `'Infinity'`, or a non-number value.","commonSituations":"Sentinel-value logic where `Infinity` marks 'no limit' but a config loader parsed it from JSON — JSON cannot represent Infinity, so it arrives as `null` or a string; arithmetic expected to overflow to Infinity instead producing NaN (e.g. `0/0`); mistakenly reaching for `assertInfinite` when `assertFiniteNumber` was intended.","solutions":["Verify you meant this assertion — most code wants `assertFiniteNumber`; the semantics here are inverted.","If Infinity is a sentinel from config, convert at load time: map `null`/'Infinity' → `Number.POSITIVE_INFINITY` before asserting.","Trace NaN sources (0/0, Infinity - Infinity, parse failures) if you expected an overflow to Infinity."],"exampleFix":"// before\nconst limit = config.maxItems; // null from JSON\nassertInfinite(limit);\n// after\nconst limit = config.maxItems ?? Number.POSITIVE_INFINITY;\nassertInfinite(limit);","handlingStrategy":"validation","validationCode":"if (typeof value !== 'number' || Number.isFinite(value) || Number.isNaN(value)) {\n  throw new TypeError('Expected Infinity or -Infinity');\n}","typeGuard":"function isInfiniteNumber(value: unknown): value is number {\n  return value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY;\n}","tryCatchPattern":"try {\n  assert.infinite(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* got a finite number or NaN where a sentinel Infinity was expected */ }\n  else throw error;\n}","preventionTips":["`infinite` means exactly ±Infinity — finite numbers and NaN both fail; use `is.number` for general numbers","Check `value === Infinity || value === -Infinity` before asserting","Watch arithmetic that silently produces NaN (0/0, Infinity - Infinity) instead of Infinity"],"tags":["number","infinity","json","type-assertion"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}