[BUG] Integer enum
s that don't have explicit values set produce broken types
#154
Labels
bug
Something isn't working
good first issue
Good for newcomers
keepalive
Will not be closed by Stale bot
Is there an existing issue for this?
Nature of Your Project
JavaScript, TypeScript
Current Behavior
When defining an integer enum without explicitly assigning values to the keys, the generated types will contain syntax errors (see repro for a sample model).
These enums can be compiled without issue, although the output looks a bit unexpected:
Expected Behavior
Expected output is not clear either. I would have expected to have the keys enumerated in order, starting from 0 (or 1?). The type should be set accordingly.Log a fatal error prompting the user to explicitly define values. See comment below. Type could be just
number
iff we want to make sure the run produces syntactically correct types even in this case.Steps To Reproduce
Environment
Repository Containing a Minimal Reproducible Example
No response
Anything else?
This is probably a rather easily fixable issue by iterating over the entries of integer enums and coalescing the values with their respective index.
https://github.com/cap-js/cds-typer/blob/main/lib/components/enum.js
The text was updated successfully, but these errors were encountered: