The implementation isn't even that horrible. Ignoring the integer list. That workaround is still hillarious to me.
Anyway, it seems both impressive that someone did this and that it actually works. Weird how typescript has the nicest typelevel programming I know, even nicer than some dependent ones. It probably is the only language one where autocompletion properly works with computed types?
You're making me blush! The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic. Might run into recursion limits though.
Not really. In the Typescript type system tuple types are array types where the length is encoded in the type system. Tuple types can be “added” by concatenation to produce a new tuple type:
type two = [0, 0]
type three = [0, 0, 0]
type five = [...two, ...three]
type TupleToNumber = T[“length”]
const num: TupleToNumber = 5
Comments (191) 32 threads
Show all comments
Showing thread 2 of 32
Anyway, it seems both impressive that someone did this and that it actually works. Weird how typescript has the nicest typelevel programming I know, even nicer than some dependent ones. It probably is the only language one where autocompletion properly works with computed types?
You're making me blush!
The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic. Might run into recursion limits though.
Is that anything like church encoding?
https://www.wikiwand.com/en/Church_encoding#/Church_numerals
Continue this thread — 3 replies