この課題ではTypeScript 4.0が推奨されます
カリー化とは、複数の引数を取る関数を、それぞれの 1 つの引数を取る関数の列に変換するテクニックです。
例えば:
const add = (a: number, b: number) => a + b
const three = add(1, 2)
const curriedAdd = Currying(add)
const five = curriedAdd(2)(3)
Currying に渡された関数は複数の引数を持つ場合があり、正しく型を付ける必要があります。
この課題では、カリー化された関数は一度に 1 つの引数しか受け付けません。すべての引数が代入されたら、その結果を返す必要があります。
import type { Equal, Expect } from '@type-challenges/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>>,
]