cap-js / cds-typer

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

[BUG][Regression] Incorrect types generated when using type references #224

Closed tsteckenborn closed 2 months ago

tsteckenborn commented 2 months ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

Given entities such as:

      entity TestNamespace.Test {
        key someId         : String not null @mandatory;
            someOtherField : String;
        }

You could use type reference in the following way:

 function functionTest(ID : TestNamespace.Test:someId, someOtherProp : TestNamespace.Test:someOtherField) returns array of String;

This results in the types being constructed like this:

export declare const functionTest: { (ID: _LandscapeService_TestNamespace.Test, someOtherProp: _LandscapeService_TestNamespace.Test | null): Array<string>, __parameters: {ID: _LandscapeService_TestNamespace.Test, someOtherProp: _LandscapeService_TestNamespace.Test | null}, __returns: Array<string>, kind: 'function'};

So the parameter is seen as

const functionTest: {
    (ID: Test, someOtherProp: Test | null): string[];
    __parameters: {
        ID: Test;
        someOtherProp: Test | null;
    };
    __returns: string[];
    kind: "function";
}

Expected Behavior

I'd expect it to be as it was in version 0.15 with both being typed as strings.

Steps To Reproduce

See above

Environment

- **OS**: MacOS
- **Node**: 20.12.2
- **npm**: /
- **cds-typer**: 20.0.1
- **cds**: 7.8.1

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

daogrady commented 2 months ago

This looks like it is related to https://github.com/cap-js/cds-typer/issues/223

daogrady commented 2 months ago

Hi Tobias,

I have prepared a fix which I will release later this day: https://github.com/cap-js/cds-typer/pull/227 Feel free to try it out beforehand on your model.

Best, Daniel

tsteckenborn commented 2 months ago

At a first glimpse the fix looks fine for me.

daogrady commented 2 months ago

Great, thanks for checking! I'll release this as soon as the reporter of #223 also confirms so we can hopefully unblock you asap.