Currying 1
提出詳細
type CurriedImpl<T extends readonly unknown[], R> = T extends [infer T1, ...infer T2] ? T2 extends [] ? (arg: T1) => R : (arg: T1) => CurriedImpl<T2, R> : () => R type Curried<F> = F extends (...args: infer T) => infer R ? CurriedImpl<T, R> : never declare function Currying<F>(fn: F): Curried<F>
提出日時 | 2023-09-18 15:00:06 |
---|---|
問題 | Currying 1 |
ユーザー | sankantsu |
ステータス | 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 >>, ]