diff --git a/src/curry.ts b/src/curry.ts index cb76ceec..7d3fd573 100644 --- a/src/curry.ts +++ b/src/curry.ts @@ -380,13 +380,28 @@ export function compose(...funcs: ((...args: any[]) => any)[]) { return funcs.reverse().reduce((acc, fn) => fn(acc)) } -export const partial = ( +/** + * This type produces the type array of TItems with all the type items + * in TItemsToRemove removed from the start of the array type. + * + * @example + * ``` + * RemoveItemsInFront<[number, number], [number]> = [number] + * RemoveItemsInFront<[File, number, string], [File, number]> = [string] + * ``` + */ +type RemoveItemsInFront< + TItems extends any[], + TItemsToRemove extends any[] +> = TItems extends [...TItemsToRemove, ...infer TRest] ? TRest : TItems + +export const partial = , R>( fn: (...args: T) => R, - ...args: Partial + ...args: TA ) => { - return (...rest: T) => fn(...([...args, ...rest] as T)) + return (...rest: RemoveItemsInFront) => + fn(...([...args, ...rest] as T)) } - /** * Like partial but for unary functions that accept * a single object argument diff --git a/src/tests/curry.test.ts b/src/tests/curry.test.ts index 8b7dc25d..e4a540fb 100644 --- a/src/tests/curry.test.ts +++ b/src/tests/curry.test.ts @@ -166,7 +166,8 @@ describe('curry module', () => { test('passes single args', () => { const add = (a: number, b: number) => a + b const expected = 20 - const result = (_.partial(add, 10) as any)(10) + const partialed = _.partial(add, 10) + const result = partialed(10) assert.equal(result, expected) }) test('passes many args', () => {