Lurker News

Comments (191) 32 threads

Show all comments

Showing thread 2 of 32

Tarean1 reply#
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?

phpnode1 reply#
> The implementation isn't even that horrible

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.

jitl3 replies#
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

Continue this thread — 3 replies