cds-typer
cds-typer copied to clipboard
[BUG] `type.type.startsWith not a function` for type-of+enum inside parameters
Is there an existing issue for this?
- [X] I have searched the existing issues
Nature of Your Project
JavaScript
Current Behavior
Given following CDS snippet:
entity EnumTypeOf {
str: String;
}
service EnumsInActions {
action EnumInParamAndReturn(
Param: EnumTypeOf:str enum { a; }
) returns String;
}
using cds-type's CLI, it crashes:
$ ./lib/cli.js --outputDirectory tmp --propertiesOptional true Enums.cds
[ERROR] Derived singular 'EnumTypeOf' for your entity 'EnumTypeOf', already exists. The resulting types will be erronous. Consider using '@singular:'/ '@plural:' annotations in your model or move the offending declarations into different namespaces to resolve this collision.
/Users/<dir>/cds-typer/lib/visitor.js:322
return type.enum && type.type.startsWith('cds.')
^
TypeError: type.type.startsWith is not a function
at #stringifyFunctionParamType (/Users/<dir>/cds-typer/lib/visitor.js:322:39)
at /Users/<dir>/cds-typer/lib/visitor.js:314:53
at Array.map (<anonymous>)
at #stringifyFunctionParams (/Users/<dir>/cds-typer/lib/visitor.js:312:18)
at #printFunction (/Users/<dir>/cds-typer/lib/visitor.js:332:53)
at Visitor.visitEntity (/Users/<dir>/cds-typer/lib/visitor.js:413:36)
at Visitor.visitDefinitions (/Users/<dir>/cds-typer/lib/visitor.js:96:22)
at new Visitor (/Users/<dir>/cds-typer/lib/visitor.js:85:14)
at compileFromCSN (/Users/<dir>/cds-typer/lib/compile.js:68:23)
at compileFromFile (/Users/<dir>/cds-typer/lib/compile.js:50:12)
Node.js v20.11.1
Expected Behavior
I expected the CLI to not crash and to end up with valid TypeScript files. Related issue (without the crash). https://github.com/cap-js/cds-typer/issues/169
Steps To Reproduce
- Create a file
Enum.cds
with:
entity EnumTypeOf {
str: String;
}
service EnumsInActions {
action EnumInParamAndReturn(
Param: EnumTypeOf:str enum { a; }
) returns String;
}
- Inside this repository, run
$ ./lib/cli.js --outputDirectory tmp --propertiesOptional true Enums.cds
- See crash
Environment
- OS: macOS
- Node: v20
- npm: 10.4.0
-
cds-typer: latest
main
branch ( 462d0666b6416416bda00c92124f5d210b3082a4 ) - cds: n/a (using cds-typer's CLI)
Repository Containing a Minimal Reproducible Example
See example above
Anything else?
No response