From ee45d6ce05b45fe63e7e82cd38656b93171dbcb4 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Mills Date: Fri, 23 Aug 2019 17:33:05 +0200 Subject: [PATCH] fix(ramda): bump ts-toolbelt version, restore broken examples (#37849) * revert broken curry tests, upgrade ts-toolbelt * fix typo * fix typo --- types/ramda/package.json | 2 +- types/ramda/ramda-tests.ts | 22 +++++--- types/ramda/tools.d.ts | 111 ------------------------------------- 3 files changed, 15 insertions(+), 120 deletions(-) diff --git a/types/ramda/package.json b/types/ramda/package.json index a8df43e850..57a474b0ef 100644 --- a/types/ramda/package.json +++ b/types/ramda/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "ts-toolbelt": "^3.2.22" + "ts-toolbelt": "^3.8.4" } } diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index c085e45a89..b01a39b63b 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -74,14 +74,20 @@ class F2 { const x1: (a: number, b: number, c: number, d: number) => number = R.curry(addFourNumbers); // because of the current way of currying, the following call results in a type error - // const x2: Function = R.curry(addFourNumbers)(1,2,4) - // const x3: (c: number, d: number) => number = R.curry(addFourNumbers)(1)(2); - // const x4: (d: number) => number = R.curry(addFourNumbers)(1)(2)(3); - const y1: number = R.curry(addFourNumbers)(1)(2)(3)(4); - const y2: number = R.curry(addFourNumbers)(1, 2)(3, 4); - const y3: number = R.curry(addFourNumbers)(1, 2, 3)(4); - const y4: number = R.curry(addTenFixedNumbers)(R.__, 1, 2)(0)(3)(R.__, R.__)(R.__, 5)(4)(6, 7)(R.__)(8, R.__, R.__)(9, 10); - const y5: number = R.curry(addTenFixedNumbers)(R.__, 1, R.__)(R.__, 2)(0, 3)(R.__, 5)(4, R.__)(R.__)(6, R.__, 8, 9, 10)(7); + const x2: (...args: any) => any = R.curry(addFourNumbers)(1, 2, 4); + const x3: (c: number, d: number) => number = R.curry(addFourNumbers)(1)(2); + const x4: (d: number) => number = R.curry(addFourNumbers)(1)(2)(3); + const y1: number = R.curry(addFourNumbers)(1)(2)(3)(4); + const y2: number = R.curry(addFourNumbers)(1, 2)(3, 4); + const y3: number = R.curry(addFourNumbers)(1, 2, 3)(4); + const y4: number = R.curry(addTenFixedNumbers)(R.__, 1, 2)(0)(3)( + R.__, + R.__, + )(R.__, 5)(4)(6, 7)(R.__)(8, R.__, R.__)(9, 10); + const y5: number = R.curry(addTenFixedNumbers)(R.__, 1, R.__)(R.__, 2)( + 0, + 3, + )(R.__, 5)(4, R.__)(R.__)(6, R.__, 8, 9, 10)(7); R.nAry(0); R.nAry(0, takesNoArg); diff --git a/types/ramda/tools.d.ts b/types/ramda/tools.d.ts index 4739288851..b15b813e7d 100644 --- a/types/ramda/tools.d.ts +++ b/types/ramda/tools.d.ts @@ -1,116 +1,5 @@ /// -// All the following types are explained here: -// https://medium.freecodecamp.org/typescript-curry-ramda-types-f747e99744ab -// https://github.com/pirix-gh/medium/blob/master/types-curry-ramda/src/index.ts declare namespace Tools { - type Head = - T extends [any, ...any[]] - ? T[0] - : never; - - type Tail = - ((...t: T) => any) extends ((_: any, ...tail: infer TT) => any) - ? TT - : []; - - type HasTail = - T extends ([] | [any]) - ? false - : true; - - type Last = { - 0: Last>; - 1: Head; - }[ - HasTail extends true - ? 0 - : 1 - ]; - - type Length = - T['length']; - - type Prepend = - ((head: E, ...args: T) => any) extends ((...args: infer U) => any) - ? U - : T; - - type Drop = { - 0: Drop, Prepend>; - 1: T; - }[ - Length extends N - ? 1 - : 0 - ]; - - type Cast = X extends Y ? X : Y; - - type Pos = - Length; - - type Next = - Prepend; - - type Prev = - Tail; - - type Iterator = { - 0: Iterator, Next>; - 1: From; - }[ - Pos extends Index - ? 1 - : 0 - ]; - - type Reverse = { - 0: Reverse], R>, Next>; - 1: R; - }[ - Pos extends Length - ? 1 - : 0 - ]; - - type Concat = - Reverse extends infer R ? Cast : never, T2>; - - type Append = - Concat; - type ValueOfRecord = R extends Record ? T : never; } - -declare namespace Curry { - type GapOf = - T1[Tools.Pos] extends R.Placeholder - ? Tools.Append], TN> - : TN; - - type GapsOf = { - 0: GapsOf extends infer G ? Tools.Cast : never, Tools.Next>; - 1: Tools.Concat, T2> extends infer D ? Tools.Cast : never>; - }[ - Tools.Pos extends Tools.Length - ? 1 - : 0 - ]; - - type PartialGaps = { - [K in keyof T]?: T[K] | R.Placeholder - }; - - type CleanedGaps = { - [K in keyof T]: NonNullable - }; - - type Gaps = CleanedGaps>; - - type Curry any)> = - (...args: Tools.Cast>>, any[]>) => - GapsOf> extends [any, ...any[]] - ? Curry<(...args: GapsOf> extends infer G ? Tools.Cast : never) => ReturnType> - : ReturnType; -}