Created
November 18, 2021 03:52
-
-
Save yohamta/37e8b34fe2195cb4d30e50c3dbbaf88e to your computer and use it in GitHub Desktop.
Shitty add function in typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Len<T extends any[]> = T["length"] | |
type _Add< | |
T, | |
N1 extends Number, | |
N2 extends Number, | |
Curr1 extends any[], | |
Curr2 extends any[] | |
> = Len<Curr1> extends N1 | |
? Len<Curr2> extends N2 | |
? Len<[...Curr1, ...Curr2]> | |
: _Add<T, N1, N2, Curr1, [T, ...Curr2]> | |
: _Add<T, N1, N2, [T, ...Curr1], Curr2>; | |
type Add<N1 extends Number, N2 extends Number> = _Add<any, N1, N2, [], []> | |
type X = Add<3, 5>; // type X = 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment