-
Notifications
You must be signed in to change notification settings - Fork 0
/
00017-hard-currying-1.ts
29 lines (23 loc) · 1022 Bytes
/
00017-hard-currying-1.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'
const curried1 = Currying((a: string, b: number, c: boolean) => true)
const curried2 = Currying((a: string, b: number, c: boolean, d: boolean, e: boolean, f: string, g: boolean) => true)
const curried3 = Currying(() => true)
type cases = [
Expect<Equal<
typeof curried1, (a: string) => (b: number) => (c: boolean) => true
>>,
Expect<Equal<
typeof curried2, (a: string) => (b: number) => (c: boolean) => (d: boolean) => (e: boolean) => (f: string) => (g: boolean) => true
>>,
Expect<Equal<typeof curried3, () => true>>,
]
// ============= Your Code Here =============
type Curry<T> = T extends (...params: infer Params) => infer Return
? Params extends [infer First, ...infer Rest]
? (param: First) => Rest['length'] extends 0 ? Return : Curry<(...params: Rest) => Return>
: () => Return
: never
declare function Currying<T>(fn: T): Curry<T>
type test1 = typeof curried1
type test2 = typeof curried3