ts-toolbelt icon indicating copy to clipboard operation
ts-toolbelt copied to clipboard

Infering an F.Curry type as it's "full" signature results in unexpected behavior

Open regevbr opened this issue 3 years ago • 3 comments

🐞 Bug Report

Describe the bug

Inferring a curry "full" signature type results in parameters being inferred as unknown.

Reproduce the bug

// @ts-ignore
const sorter = (a: string, b: string) => 1;
const curriedSorter = curry(sorter)

const sort = <T>(fn: (a: T, b: T) => number, list: T[]): T[] => {
    list.sort(fn)
    return list
}
const curriedSort = curry(sort)
const test041: string[] = curriedSort(curriedSorter)(['a', 'b'])

produces the following error:

tests/Function.ts:93:13 - error TS2345: Argument of type 'Curry<(a: string, b: string) => number>' is not assignable to parameter of type 'x | ((a: unknown, b: unknown) => number)'.
  Type 'Curry<(a: string, b: string) => number>' is not assignable to type '(a: unknown, b: unknown) => number'.
    Types of parameters 'a' and 'a' are incompatible.
      Type 'unknown' is not assignable to type 'string | x'.
        Type 'unknown' is not assignable to type 'x'.
          Type 'unknown' is not assignable to type 'unique symbol'.

93 curriedSort(curriedSorter)

Expected behavior

Should compile properly

Possible Solution

Add the full signature as an overload (using intersection doesn't work!)

Additional context

The issue was discovered during the work on https://github.com/DefinitelyTyped/DefinitelyTyped/pull/53478

regevbr avatar Jun 01 '21 20:06 regevbr

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 03 '21 02:08 stale[bot]

@millsp can you please address this?

regevbr avatar Aug 18 '21 07:08 regevbr

Any updates on this? 🙈

sant123 avatar Oct 15 '21 15:10 sant123