You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search Terms: nested typeguard type guard depending infer generic
Code
interfaceA{b: {a: 12;b: 22;}c: {r: 33;}}functiontestFn<TextendskeyofA>(param1: T,param2: keyofA[T]){if(param1==='b'){// here should infer param2: 'a' | 'b' but it doesn'tassertName(param2);}}functionassertName(name: 'a'|'b'){}
TypeScript Version: 3.1.0-dev.201xxxxx
Search Terms: nested typeguard type guard depending infer generic
Code
Expected behavior:
param2 type inferred
Actual behavior:
param2 type is string | number | symbol
Playground Link: https://www.typescriptlang.org/play/index.html#src=interface%20A%20%7B%0D%0A%20%20b%3A%20%7B%0D%0A%20%20%20%20a%3A%2012%3B%0D%0A%20%20%20%20b%3A%2022%3B%0D%0A%20%20%7D%0D%0A%20%20c%3A%20%7B%0D%0A%20%20%20%20r%3A%2033%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0Afunction%20testFn%3CT%20extends%20keyof%20A%3E(param1%3A%20T%2C%20param2%3A%20keyof%20A%5BT%5D)%20%7B%0D%0A%20%20%20%20if%20(param1%20%3D%3D%3D%20'b')%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20here%20should%20infer%20param2%3A%20'a'%20%7C%20'b'%20but%20it%20doesn't%0D%0A%20%20%20%20%20%20%20%20assertName(param2)%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Afunction%20assertName(name%3A%20'a'%20%7C%20'b')%20%7B%0D%0A%0D%0A%7D
Related Issues:
The text was updated successfully, but these errors were encountered: