Re:Functions and algorithms implemented purely with TypeScri...
by mozey on Wednesday July 05, 2023 @12:41AM
(#36595580)
"This project attempts to push TypeScript's type system to its limits by actually implementing various functions and algorithms, purely on top of the type system... Please note that this project is meant to be used for fun and learning purposes and not for practical use"
Re:Functions and algorithms implemented purely with TypeScri...
by spencerchubb on Wednesday July 05, 2023 @12:43AM
(#36595594)
It is indeed interesting! I was just trying to analyze it a bit deeper
Re:Functions and algorithms implemented purely with TypeScri...
by n_e on Wednesday July 05, 2023 @01:59AM
(#36596047)
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>
Re:Functions and algorithms implemented purely with TypeScri...
by dqbd on Wednesday July 05, 2023 @03:06AM
(#36596614)
A 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/...
https://github.com/ronami/meta-typing/blob/master/src/utils/...