-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
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.
Azarattum
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed