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
Expected behavior:
The var key should have type keyof typeof myObj evaluating to 'a' | 'b' | 'c' instead of just string. This would then allow the use of myObj[key] without having to cast to any
ie (myObj as any)[key]
The text was updated successfully, but these errors were encountered:
Unfortunately this wouldn't be appropriate behavior - if you have a subtype of MyInterface (i.e. a type that's more specific than MyInterface), then the keys of myObj actually grow, which gives you a less specific type.
So you might think that at runtime your keys are a, b, and c, but in reality you might also have a d, e, and f property as well.
TypeScript Version: 2.2.2
Code
Expected behavior:
The var
key
should have typekeyof typeof myObj
evaluating to'a' | 'b' | 'c'
instead of juststring
. This would then allow the use ofmyObj[key]
without having to cast to anyie
(myObj as any)[key]
The text was updated successfully, but these errors were encountered: