We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
T & U
T
U
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
Playground link
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
The text was updated successfully, but these errors were encountered:
This is an issue with how we break down intersection types in type inference. Here's a simpler repro:
declare function f<T>(x: { prop: T }): T; declare const a: { prop: string } & { prop: number }; declare const b: { prop: string & number }; f(a); // string f(b); // string & number
We obviously shouldn't deliver different results above. Both should be string & number.
string & number
Sorry, something went wrong.
swap order of merged types to work around microsoft/TypeScript#18354
10328bd
Thanks for the quick fix. I can confirm this is working in [email protected]
[email protected]
ahejlsberg
No branches or pull requests
TypeScript Version: 2.5.x, 2.6.0-dev.20170908
When passed as an argument,
T & U
evaluates toT
, and the typeU
is discarded.Playground link
Workarounds
Specify the type arguments explicitly:
An identity type mapping can be used to create an intermediate type
Related issue typed-ember/ember-typings#32
The text was updated successfully, but these errors were encountered: