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
Type narrowing does not occur for indexed access forms e[k] where k is not a literal.
See also #31445 and #34867. At present, the compiler can't safely narrow these expressions because it only cares about the types and doesn't track the specific k variable used. test2[string] casts too wide a net to serve as a type guard.
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms: ts2531 possibly null
Code
Expected behavior: No error
Actual behavior: TS2531 happened on
function check2
's console logging code. (${obj[key] + 10}
)Playground Link: Here
Related Issues: #28131
The text was updated successfully, but these errors were encountered: