cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
29 stars 10 forks source link

[BUG] Duplicate Identifier generated when using many to many Composition #314

Closed MichaelFlucher closed 1 month ago

MichaelFlucher commented 2 months ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

The generated types of the SampleService include an empty type Teams and a class Teams, causing the error Duplicate identifier 'Teams'.

export type Teams = {};
export class Teams extends Array<Team> {$count?: number}

Expected Behavior

Don't include export type Teams = {}; or don't cause an typescript error

Steps To Reproduce

  1. Include the many-to-many sample in the database schema.cds
  2. Expose both entities in the Service
  3. Generate the types

Environment

- **OS**: macOS
- **Node**: 20.12.2
- **npm**: 10.8.0
- **cds-typer**: 0.25.0
- **cds**: 8.2.1

Repository Containing a Minimal Reproducible Example

https://github.com/MichaelFlucher/cds-typer-issue

Anything else?

It works if we don't expose the entity containing the Composition: https://github.com/MichaelFlucher/cds-typer-issue/blob/working-sample/srv/sample-service.cds

MichaelFlucher commented 2 months ago

Sample code for many-to-many relationship taken from https://cap.cloud.sap/docs/cds/cdl#for-many-to-many-relationships

daogrady commented 1 month ago

Hi Michael,

thanks for reporting this issue and for attaching a minimal reproducible sample! I have prepared a fix for this problem. Feel free to try it out before I merge it.

Best, Daniel

MichaelFlucher commented 1 month ago

Hi Daniel, I testet it with the sample and also in a bigger project. Works in both cases 👍🏽

daogrady commented 1 month ago

Great news! I will then merge the fix and include it in the next release. Thanks for testing