-
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 issue
Milestone
Description
TypeScript Version: 2.5.x, 2.6.0-dev.20170908
When passed as an argument, T & U
evaluates to T
, and the type U
is discarded.
declare function f<T, Key extends keyof T>(obj: {[K in keyof T]: T[K]}, key: Key): T[Key];
declare const obj: { a: string } & { b: string };
f(obj, 'a');
f(obj, 'b'); // error
Workarounds
Specify the type arguments explicitly:
f<typeof obj, keyof typeof obj>(obj, 'b');
An identity type mapping can be used to create an intermediate type
type Fix<T> = {[P in keyof T]: T[P]}
declare const obj: Fix<{ a: string } & { b: string }>;
f(obj, 'a');
f(obj, 'b');
Related issue typed-ember/ember-typings#32
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