Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

there is wrong with CurryV5 #6

Open
MuYunyun opened this issue Aug 1, 2021 · 0 comments
Open

there is wrong with CurryV5 #6

MuYunyun opened this issue Aug 1, 2021 · 0 comments

Comments

@MuYunyun
Copy link

MuYunyun commented Aug 1, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant