-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.8.0-dev.20180201
Search Terms: generic parameter default infer keyof 2.7
Code
interface X {
a: string;
b: string;
}
function foo<T = X>(x: keyof T, y: keyof T) { }
foo<X>('a', 'b'); // compiles cleanly
foo('a', 'b'); // error TS2345: Argument of type '"b"' is not assignable to parameter of type '"a"'.Expected behavior:
Both calls to foo() compile with no errors.
Actual behavior:
In the second call, when the generic parameter T is not set explicitly, an error occurs: error TS2345: Argument of type '"b"' is not assignable to parameter of type '"a"'.
It seems that since 2.7, the generic parameter is tightly inferred from the first parameter to be something like {a: string}, so the default (which would have been compatible with both parameters) is not used.
This error does not occur in version 2.6.2. It does occur in version 2.7.1 and 2.8.0-dev.20180201.
Related Issues:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue