Skip to content

Return type of partially applied bound generic functionΒ #47899

Closed

Description

Bug Report

πŸ”Ž Search Terms

partial application generic bind return type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about bind, generics, partial application

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function a<T extends Array<any>>(anArray: T): T {
    return anArray;
}

let b = a.bind(undefined, [1]); // b has type () => any[]
let c = () => a([1]);           // c has type () => number[]


// Further simplified

function identity<Type>(arg: Type): Type {
  return arg;
}

let d = identity.bind(undefined, "test"); // d has type () => unknown
let e = () => identity("test");           // e has type () => string

πŸ™ Actual behavior

The types of b and c are different, and the types of d and e are different.

πŸ™‚ Expected behavior

I'd expect them to both have the same type (b that of c, () => number[]), d that of e () => string), as the expressions are doing the same thing (arrow function vs bind for partial application of a function).

This limitation is noted in a comment to the "Strict bind, call, and apply methods on functions" PR, but I couldn't find an actual issue referencing this behaviour.
That comment is also mentioned as a known limitation in a similar issue which was closed in #28920, but unfortunately that pr only fixes the issue when binding only this, and not other parameters.

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

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions