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
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)
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
The text was updated successfully, but these errors were encountered:
What
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
Examples
See my attempt here
My attempt for
PositiveIntegerString
The text was updated successfully, but these errors were encountered: