Skip to content

there is wrong with CurryV5 #6

Description

@MuYunyun

typescript version: 4.3.5

hi, it seems there is wrong with CurryV5 if using as follow:

- const toCurry09 = (name: string, age: number, single: boolean, ...nicknames: string[]) => true
+ const toCurry09 = (name: string, age: number, ...nicknames: string[]) => true

- const test47 = curried09('Jane', 26)(true, 'JJ', 'Jini') // boolean
- const test48 = curried09('Jane')(26, true, 'JJ', 'Jini') // boolean
- const test49 = curried09('Jane')(26)(true, 'JJ', 900000) // error 

+ const test47 = curried09('Jane', 26)('JJ', 'Jini') // boolean
+ const test48 = curried09('Jane')(26, 'JJ', 'Jini') // boolean
+ const test49 = curried09('Jane')(26)('JJ', 900000) // error

image

here is complete examples:

type CurryV5<P extends any[], R> =
  <T extends any[]>(...args: Cast<T, Partial<P>>) =>
    Drop<Length<T>, P> extends [any, ...any[]]
    ? CurryV5<Drop<Length<T>, P> extends infer DT ? Cast<DT, any[]> : never, R>
    : R

// When all the non-rest parameters are consumed, `Drop<Length<T>, P>` can only
// match `[...any[]]`. Thanks to this, we used `[any, ...any[]]` as a condition
// to end the recursion.

// Let's test it:
declare function curryV5<P extends any[], R>(f: (...args: P) => R): CurryV5<P, R>

const toCurry09 = (name: string, age: number, ...nicknames: string[]) => true
const curried09 = curryV5(toCurry09)

const test47 = curried09('Jane', 26)('JJ', 'Jini') // boolean
const test48 = curried09('Jane')(26, 'JJ', 'Jini') // boolean
const test49 = curried09('Jane')(26)('JJ', 900000) // error

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions