Like happens with const variable typeguards that keep applying inside new function-like bodies, I would expect the same for const object literal's readonly properties
TypeScript resets narrowing within the scope of a function because it cannot be sure that the outer scope checks are valid when the resulting function is invoked.
See #11498
Correct me if i'm wrong, but the combine use of readonly and const should guarantee that root.foo2 is not undefined. #11498 addresses the case when the root variable is not constof the property is not readonly.
Just because you have a readonly reference to an object doesn't mean someone else doesn't have a mutable reference to it
Ah, I didn't think of that. Thanks for the explanation.
aja, got it thanks! Should I close this issue ?
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Most helpful comment
Just because you have a
readonlyreference to an object doesn't mean someone else doesn't have a mutable reference to it