Skip to content

fix(type): add number.finite keyword to reject Infinity and NaN#1605

Open
WolfieLeader wants to merge 6 commits intoarktypeio:mainfrom
WolfieLeader:feat/number-finite-keyword
Open

fix(type): add number.finite keyword to reject Infinity and NaN#1605
WolfieLeader wants to merge 6 commits intoarktypeio:mainfrom
WolfieLeader:feat/number-finite-keyword

Conversation

@WolfieLeader
Copy link

Summary

Closes #1598

Adds number.finite keyword that rejects NaN, Infinity, and -Infinity. Matches Number.isFinite() semantics.

Implementation follows the number.safe pattern exactly:

  • numberAllowsNaN: false on the domain node (rejects NaN)
  • min/max bounds at ±Number.MAX_VALUE with custom meta: "a finite number" (rejects ±Infinity with a clear error message)

Using min/max rather than a predicate ensures the constraint is composable (intersects with user bounds), JIT-compiled, introspectable, and compatible with the fast-check arbitrary generator.

Error messages:

  • Infinity"must be a finite number (was Infinity)"
  • -Infinity"must be a finite number (was -Infinity)"
  • NaN"must be a number (was NaN)" (domain-level rejection)

Test plan

  • Finite numbers accepted (integers, floats, zero, ±MAX_VALUE boundary)
  • ±Infinity rejected with descriptive error
  • NaN rejected at domain level
  • pnpm prChecks passes (format, lint, typecheck, full test suite)

Matches the pattern used by number.safe. min/max bounds are composable,
JIT-compiled, and introspectable by the fast-check arbitrary generator.
@github-project-automation github-project-automation bot moved this to To do in arktypeio Mar 19, 2026
@WolfieLeader WolfieLeader changed the title feat(type): add number.finite keyword to reject Infinity and NaN fix(type): add number.finite keyword to reject Infinity and NaN Mar 19, 2026
Copy link
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation that mirrors the number.safe pattern. One required change: allConfig.ts must be regenerated to include "number.finite", otherwise the testAllConfig integration test will fail (pnpm testRepopnpm testIntegrationpnpm testAllConfig).

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow runpullfrog.com𝕏

root: intrinsic.number,
integer,
epoch,
finite,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allConfig.ts is a checked-in generated file that the testAllConfig integration test uses to verify every keyword has a "configured" description. It currently does not include "number.finite", so the test will fail.

Run the generator to update it:

pnpm tsx ark/type/__tests__/integration/generateAllConfig.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

Make "number" reject Infinity, or make it easy to parse only finite numbers

1 participant