Skip to content

Inferred type of union with readonly properties is dependent on declaration order #46814

Closed
@EricCornelson

Description

@EricCornelson

Bug Report

🔎 Search Terms

union, readonly, order

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about unioned readonly properties

Playground link with relevant code

💻 Code

image

🙁 Actual behavior

The order of the declaration of the variables one and two affects whether the compiler will treat the property a as readonly. Also, the order of each variable in the conditional for the return type of doSomething affects the inferred return type (i.e. whether a is displayed as readonly or not)

Finally, when one is first in the conditional, the displayed type of a is any

🙂 Expected behavior

I would not expect the declaration order nor the conditional order to affect whether the property is considered readonly.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions