cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
25 stars 8 forks source link

[BUG] Composition of many in edge cases deviating singulars derived leading to type errors #229

Closed tsteckenborn closed 1 month ago

tsteckenborn commented 2 months ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

Given the following:

service test {
    entity TestEntityEndingOnses {
        key id            : String;
            testProperty1 : Composition of many TestEntityEndingOnses
    }
}

leads to the following being generated:

// This is an automatically generated file. Please do not change its contents manually!
import * as __ from './../_';
export default { name: 'test' }
export function _TestEntityEndingOnsAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
  return class TestEntityEndingOns extends Base {
        id?: string;
        testProperty1?: __.Composition.of.many<TestEntityEndingOnses>;
      static readonly actions: Record<never, never>
  };
}
export class TestEntityEndingOns extends _TestEntityEndingOnAspect(__.Entity) {}
Object.defineProperty(TestEntityEndingOns, 'name', { value: 'test.TestEntityEndingOnses' })
export class TestEntityEndingOnses extends Array<TestEntityEndingOns> {$count?: number}
Object.defineProperty(TestEntityEndingOnses, 'name', { value: 'test.TestEntityEndingOnses' })

Where in the line export class TestEntityEndingOns extends _TestEntityEndingOnAspect(__.Entity) {} it should be ...extends _TestEntityEndingOns<--....

Expected Behavior

It would have been expected that the generated types would be consistent and not incorrect.

Steps To Reproduce

See above.

Environment

- **OS**: MacOs
- **Node**: 20.12.2
- **npm**:
- **cds-typer**: 0.20.2
- **cds**: 7.8.2

Repository Containing a Minimal Reproducible Example

No response

Anything else?

You can work around that by specifying the @singular on the respective entity.

daogrady commented 1 month ago

Hi Tobias,

thanks for this report! I have prepared a fix which you can try on your actual model before I release it, if you would like.

Best, Daniel