Type Challenges Judge

Currying 1

提出詳細

type Currying<T> = T extends (...arg: infer Arg) => infer Ret ? Arg["length"] extends 0 | 1 ? T : Arg extends [infer L, ...infer R] ? (a: L) => Currying<(...a: R) => Ret> : Ret : never; declare function Currying<T extends Function>(fn: T): Currying<T>
提出日時2023-08-30 08:06:59
問題Currying 1
ユーザーookkoouu
ステータスAccepted
テストケース
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) 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 >>, ]