Curried function type
HardP3Coding
Declare the type of a function Currying(fn) that curries fn: the returned function takes one argument at a time, in order, and the last call returns the return type of fn. A function with no parameters stays a function with no parameters.
Tests your type must pass
const curried1 = Currying((a: string, b: number, c: boolean): true => true)
const curried2 = Currying(
(a: string, b: number, c: boolean, d: boolean, e: boolean, f: string, g: boolean): true => true,
)
const curried3 = Currying((): true => true)
const curried4 = Currying((a: number): string => 'x')
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>>,
Expect<Equal<typeof curried4, (a: number) => string>>,
]Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
TypeScript
Run and Submit type-check your solution against the tests. ⌘Enter runs, ⌘⇧Enter submits.