blob: 11f40868a8454d82f5829b85f5189c11f3328a70 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
type Zero = "😰";
type Succ<N> = {prev: N};
type Prev<N> = N extends Succ<infer P> ? P : never;
type Add<A, B> = B extends Zero ? A : Succ<Add<A, Prev<B>>>;
type _Fib<N, AccumulatorA, AccumulatorB> =
N extends Zero
? AccumulatorA
: N extends Succ<Zero>
? AccumulatorB
: _Fib<Prev<N>, AccumulatorB, Add<AccumulatorA, AccumulatorB>>;
type Fib<N> = _Fib<N, Zero, Succ<Zero>>;
export type {Zero, Succ, Fib};
|