Closed
Description
Type inference exhibits strange behavior when you have an overloaded function with a generic that takes an object as an argument:
// A function that extracts the values from an object
declare function values<T>(object: { [key: number]: T }): T[];
declare function values<T>(object: { [key: string]: T }): T[];
// A type with a member called 'a'
interface MemberA {
a: number;
}
// OK
declare var numberObject: { [key: number]: MemberA };
values(numberObject).map(value => value.a);
// Error, infers value : {}
declare var stringObject: { [key: string]: MemberA };
values(stringObject).map(value => value.a);
It seems to be just choosing the first overload.