-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification
Milestone
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.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification