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
{{ message }}
Repository navigation
Type guards don't work on key/value objects #14957
lettest: string;constobj1: {val: string|number}={val: ''};if(typeofobj1.val==='string'){test=obj1.val;// => Works fine}constobj2: {[k: string]: string|number}={val: ''};if(typeofobj2.val==='string'){test=obj2.val;// => Type 'string | number' is not assignable to type 'string'}
Expected behavior:
Type guards to work on key/value objects
Actual behavior:
Can't infer the correct type after check
Interesting. This will likely require some architectural changes as we currently have no symbol to associate with the .val property access and thus nothing to narrow by.
Activity
RyanCavanaugh commentedon Apr 3, 2017
Interesting. This will likely require some architectural changes as we currently have no symbol to associate with the
.valproperty access and thus nothing to narrow by.RyanCavanaugh commentedon Jul 22, 2020
This works now