You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regex \d+ infers ${number}, which rejects valid digit strings longer than ~309 digits #1663
regex, \d+, ${number}, Infinity, long digit string, arkregex, never incorrect
🧩 Context
ArkType version: 2.2.5 (arkregex 0.0.10)
TypeScript version (5.1+): 5.1.6, 5.3.3, 5.4.5, 5.9.3, 7.0.2, 7.1.0-dev.20260926.1 (same result on each; ${number} rejecting non-finite strings is standard TypeScript behavior, so this isn't version-specific)
Other context you think may be relevant (JS flavor, OS, etc.): Node 24, macOS
🧑💻 Repro
Playground Link: N/A. The playground doesn't resolve regex types yet (regex() is any there, see #1529, and type("/^\\d+$/") reports "not allowed here"), so the repro below was verified with a local install of arktype@2.2.5 instead.
import{type}from"arktype"constDigits=type("/^\\d+$/")typeDigits=typeofDigits.infer// `${number}`// "1" followed by 309 zerosconstbig="1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"Digits(big)// passes validation and returns the stringconstx: Digits=big// ❌ Type '"1000…0"' is not assignable to type '`${number}`'
A string is only a ${number} if Number(s) is finite, and Number(big) is Infinity. So any digit run above ~1.8e308 passes validation but isn't assignable to the inferred type. The same happens with regex("^\\d+$"), with \d*, and with digit runs inside larger patterns such as ^v\d+\.\d+$ and the semver core regex.
It's an edge case, but it breaks the guarantee from the ArkRegex announcement that inferred types are "at worst imprecise and never incorrect": validated data ends up typed as something it isn't.
A sound replacement for \d+ that works on every supported TS version (5.1+):
It has no length limit and still rejects things like "1e5", "0x1f" and " 1". I'm also opening a feature request with a more precise version for TS 5.3+.
Activity
pullfrog commentedon Sep 27, 2026
fix(regex): infer an unbounded run of digits as string