This solution may not be the most practical, but it addresses the TypeScript side as well. Despite its unsophisticated nature, I have devised a workaround.
Here are some limitations to consider:
- The comparison value must be less than 45
- This method only works with integers
In response to your query, using my utilities, here is the proposed solution:
// Below are the definitions of these variables that you can refer to
interface Input {
value: AllGreaterThan<1, OneToOneHundred>
}
Essentially, this approach mandates that value
be an integer ranging from 2 to 99. If you wish to delve deeper, take a look at the provided source code below. Otherwise, simply copy and paste it into an isolated environment for seamless implementation...
// For instance, "0|1|2" -> ["0", "1|2"]
type Decompose<S> = S extends `${infer FirstNumber}|${infer RestOfSet}` ? [FirstNumber, RestOfSet] : never;
// This method utilizes basic array indexing to achieve the desired outcome, although not the optimal choice
type OneHundredNumber= [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99];
type OneToOneHundred = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"10"|"11"|"12"|"13"|"14"|"15"|"16"|"17"|"18"|"19"|"20...
// @ts-expect-error: ignore because typescript requires explicit matches but it's not practical here
type DecomposedNumber<S> = ToNumber<Decompose<S>[0]>
// The maximum value allowed is 44, making this table sufficient for the task
type FortyFive = '0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|end'
type AllGreaterThan<LessThanThis extends number | string, RangeToReturn extends ...
export type OneToOneHundredNumber = 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99
export type AllIntegersInRange = AllGreaterThan<44, OneToOneHundredNumber>