Closed
Description
This is a rough sketch so I have something to refer to.
Currently, we treat the two instances of T
in the parameter list here equally:
declare function containsAny<T>(arr: T[], predicate: (x: T) => boolean): boolean;
This means that when we make a call like this:
var x = containsAny([1, 2, 3], 'hello');
we infer T
to be {}
. The first argument is assignable to {}[]
and the second argument is assignable to {}
, so the call succeeds. This is unexpected and basically wrong.
If instead we only used the type parameters from function arguments when there were no other candidates for a given type parameter, we would infer T
to be number
and the call would be correctly rejected.
Not done yet: Actual spec work, thinking it through all the way, testing against existing code.