-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00017-hard-currying-1.ts
48 lines (44 loc) · 1.04 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ============= 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<Args extends unknown[], R> = Args extends [infer Head, ...infer Tail]
? (a: Head) => Curry<Tail, R>
: R
declare function Currying<Fn extends Function>(
fn: Fn
): Fn extends (...args: infer Args) => infer R
? Args extends []
? () => R
: Curry<Args, R>
: never