This is more of a question for advanced type experts. Would it be possible to make a type that only allows positive integers in a string? E.g. "123"
and "82739283293237"
In my attempt to use template string types with many unions will hit a wall with
Expression produces a union type that is too complex to represent.(2590)
Also posted this question here
ts-essentials/ts-essentials#388
PositiveIntegerString
type Digits = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
// Problem: This pattern can not be repeated for too long...
type PositiveIntegerString =${Digits}${Digits | ''}${Digits | ''}${Digits | ''}
;function processPositiveInteger(input: PositiveIntegerString) {
console.log("Valid positive integer string:", input);
}// Example Usage:
processPositiveInteger("3"); // OK
processPositiveInteger("323"); // OK
processPositiveInteger("1323"); // OK
processPositiveInteger("1322323233"); // Should be OK but is not
processPositiveInteger("-1"); // Error
processPositiveInteger("12.34"); // Error
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too