-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Narrowing subtypes by enum values does not work #58865
Comments
@RyanCavanaugh I didn't spot this at first either - the Playground code doesn't exactly match the snippet in the OP. If I paste that code into the Playground given, I see the It seems like OP expects members of different enums with the same underlying string values to be treated as interchangeable, but that's not how |
I'm sorry, I fixed the link, it should be correct now.
Exactly, thats not how enum works in many languages like Java, where interfaces are also not interchangeable. Btw, there are no enums in Javascript, they are converted into objects. const SomeEnumA = {
Example: 'Value'
}
const SomeEnumB = {
Example: 'Value'
}
SomeEnumA.Example === SomeEnumB.Example // correct? |
The entire point of string |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
"narrow enum", "enum intersection"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBMAdgVwLZwErAM7CgNwEMYBLCRAYQAtDEBzYAFQE8xg4BvAKDjgqmDFgAEzgBeOAHJ+gmCMkAaHnAAiQ7OKlq52RcoAKhEJsmGQe3gGU8+EgGMcJ6wXs49AXy6hIsBCnRYuATEZJQCQsLUtAwsbJzKMhEmiXLCHl7g0PBIaJg4NiHk2jhR9Eys7Ny8xRoSkjXp3ll+uYEFpORmpTEV8bxmJmaNmb45AfnBHYjOtg7Y3eVxVXAzrrVSq3PpXDC9C9bwEst2NGXYAFx5QURTCwDaALpcnju9bZOhXacMmstgArYIMgLpw7EDEDBLv4AEZ4Ty8RCgSGg8HImFw5S7NiXd43T5GBaxYDPV5xXGFaY2NYLX7KQjCYQiS7YGBQEj0R7KASoCD4JlwFlsjlPXhY4A4iZ48ibErfRbEl5iq7tUI0o7KXiiioS64UwkVDVwdxwABkcAAFIbeAAfZUfcgpEQLK1wW3kqY1Z2azVuyUUr7RYnem12qWUlxzL2agCUXFJ7HdqrlB1pvGEQmZrPZdGUJ0DIMTDrlnPhcHjob14VSar6cDFOpVDqrTrlRJJ5cLiE9ctTcH+wEBwMuHFLiJAyJHmO1FY96n1bHbYMQLIFwBgIP2a8emkeAG44wAzaDmgA2a9X8AgB4v2GjtYA9Pe4HmznASBpEXyoJyLwA6F8MNgzxAA
π» Code
π Actual behavior
changes are
never[]
π Expected behavior
changes are narrowed to its subtypes and essentially
ReservationChange[]
Additional information about the issue
If use
ReservationChangeType.Created
instead ofReservationCreatedChangeType
it obviously works,However it seems it should work even if it two different enums, when their values are intersecting it should not be a problem for narrowing correct type.
The text was updated successfully, but these errors were encountered: