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
It seems related issues have been around for a long time, in addition issue #26599 was closed as a "wontfix". This is weird to me because it seems Typescript should be able to detect that objectKey has not changed between the object assignment and query.
The text was updated successfully, but these errors were encountered:
If the key is truly variable, then this is related to #31445: TS isn't equipped to understand that two mentions of obj[key] access the same property in both places; since it doesn't even know that, it doesn't make sense to perform any narrowing on it.
TypeScript Version: 3.7.0-dev.20190824
Search Terms:
Object is possibly undefined
TS2532
Code
Expected behavior:
Code compiles without error.
Actual behavior:
Error:
TS2532: Object is possibly 'undefined'.
onmyObject[objectKey]
Playground Link:
http://www.typescriptlang.org/play/index.html#code/JYOwLgpgTgZghgYwgAgJIBE5jsg3gKGWQBMs4AuZEAVwFsAjaAbnwF999RJZEVUBZAJ4B5egCsICMHkLIA2qGIQAHpQDOYKKADmAXUoYyyAD7JqIJTFARiLdvgQB7EBuS0R4yWANDREqcgAvHisLE4u0o6eUgDSEIJByADkao60EGAAFjpJLPjufl5yUf5gcYK6iQREpNiUAKxsHOGpADYQAHStjtoAFAXRYMWD5bodtXAAlExAA
Related Issues:
#13778, #17960, #26599, #29642
It seems related issues have been around for a long time, in addition issue #26599 was closed as a "wontfix". This is weird to me because it seems Typescript should be able to detect that
objectKey
has not changed between the object assignment and query.The text was updated successfully, but these errors were encountered: