3 ms·
You can count to an arbitrary number (until the recursion limit) by using tuples of length N (and go back and forth to number literals by using the type of tupl
by n_e 3y ago
You can count to an arbitrary number (until the recursion limit) by using tuples of length N (and go back and forth to number literals by using the type of tuple['length'])
e.g. :
type zero = []
type Inc<N extends string[]> = [...N,'']
type Dec<N extends string[]> = N extends [...infer T,''] ? T : never
type one = Inc<zero>
type two = Inc<one>
type oneb = Dec<two>
- dqbd 3y agoA tuple does have a upper limit of 10 000 elements, which means that with this approach we can count to 10 000 at most. Another approach which I tried is to do arithmetics on digits directly, storing digits in a tuple instead, but the code is not as elegant as the tuple one https://github.com/dqbd/ts-math-evaluate/blob/main/src/math/add.ts https://github.com/dqbd/ts-math-evaluate/blob/main/src/math/...