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
{{ message }}
Repository navigation
Not possible to use string-valued enums in another enum's definition #55978
Type 'E' is not assignable to type 'number' as required for computed enum member values.
🙂 Expected behavior
No error should appear. Nothing in that code snippets expects numbers so this message is really confusing, especially that I'm just trying to use one string-valued enum in another one.
Yeah, I discovered that as well. In real code, both E1 & enums are bigger and a part of a separate package so I'd need to change its API to export the enums directly.
Emit can't rely on type information, and the emitter needs to know whether E2.A should be a string or numeric value (since string and numeric values have different enum emit), and the only way to do that is with type information.
Activity
MartinJohns commentedon Oct 4, 2023
You can just do:
enum E2 { A = E1.A }The issue is not trying to use the value from another enum, but the indirection via a variable.mgol commentedon Oct 4, 2023
Yeah, I discovered that as well. In real code, both
E1&enumsare bigger and a part of a separate package so I'd need to change its API to export the enums directly.What's the reason for this behavior?
RyanCavanaugh commentedon Oct 4, 2023
Emit can't rely on type information, and the emitter needs to know whether
E2.Ashould be a string or numeric value (since string and numeric values have different enum emit), and the only way to do that is with type information.typescript-bot commentedon Oct 7, 2023
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.