String Enum values compile to the key rather than source value #4276
Labels
bug
This issue is a bug.
language/dotnet
Related to .NET bindings (C#, F#, ...)
language/go
Regarding GoLang bindings
language/java
Related to Java bindings
language/python
Related to Python bindings
language/ruby
Related to Ruby bindings
p1
Describe the bug
In typescript, we can represent string enums like so:
However, in all languages besides js, jsii compiles these so that the key name is used. For instance, python output looks like:
When using the enum as a type, this doesn't matter, as the literal value is unimportant. But when outputting a string, Python developers are now outputting
FOO
whereas TS/JS users of the same construct outputbar
. This breaks interoperability.Expected Behavior
The string representation of an enum value in all languages should match the source code. As noted in the jsii design tenants:
Applications should behave identically, and if that is not possible, there should be a compiler error for string enums where the key and value do not match.
Current Behavior
An application which uses runtime validation of enum values will fail in languages other than JS. For instance:
I believe this is because the JS assembly is used when calling
Object.values()
, and the value passed in doesn't match JS values due to the serialization differences.Reproduction Steps
Possible Solution
Rework how JSII models string enum values. Not sure how complicated this is, but it seems important for correctness.
Additional Information/Context
No response
SDK version used
jsii=5.2.8; jsii-pacmak=1.89.0
Environment details (OS name and version, etc.)
MacOS 11.7.10
The text was updated successfully, but these errors were encountered: