Assignment of nested field accessed from union type indexed field expects union type instead of intersection type #50249
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Bug Report
🔎 Search Terms
assignment union intersection nested get set
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
When accessing a field via any valid key that is unknown, the compiler correctly asserts that the type returned is the union of the possible types at the possible keys.
When assigning a field via any valid key that is unknown, the compiler correctly asserts that the type to be set must be the intersection of all the possible types. However, if you access a shared nested field and attempt to assign it, the expected assignment is a union type. This seems incorrect as the assignment again should be the intersection of the possible types that the shared nested property could be across all valid keys used to access the parent property.
🙂 Expected behavior
Discussed above, but again, regardless of if the field or its parent were accessed via an unknown but valid key, the expected assignment type should be an intersection, even if the intersection is
never
, as that would be the only valid way to ensure any property assigned has been given a valid value.The text was updated successfully, but these errors were encountered: