cap-js / cds-typer

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

[BUG] Generated index.ts files have syntax errors "property '_...Aspect' does not exist" #270

Closed D027152 closed 2 months ago

D027152 commented 2 months ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

In our project we have defined the aspect SourceReferences, which is used in several entities. The generated index.ts files containing these entities have al the syntax error

Property '_SourceReferenceAspect' does not exist on type 'typeof import("...

Somehow the index.ts files for the aspect seems not to be correctly generated.

Expected Behavior

The generated index.ts files shall be syntax error free.

Steps To Reproduce

repo https://github.tools.sap/erp4sme/crypto-for-business npm run cds-typer:dev generates the files into folder @cap-models Note: this script makes use of --IEEE754Compatible true in order to get cds type Decimal generated as (number | string)

Environment

| @cap-js/audit-logging  | 0.6.0                                         |
| @cap-js/cds-typer      | 0.21.2                                        |
| @cap-js/cds-types      | 0.2.0                                         |
| @cap-js/change-trackin | 1.0.5                                         |
| @cap-js/telemetry      | 0.1.0                                         |
| @sap/cds               | 7.7.3                                         |
| @sap/cds-common-conten | 1.4.0                                         |
| @sap/cds-compiler      | 4.8.0                                         |
| @sap/cds-dk            | 7.7.2                                         |
| @sap/cds-dk (global)   | 7.7.2                                         |
| @sap/cds-fiori         | 1.2.3                                         |
| @sap/cds-foss          | 5.0.0                                         |
| @sap/cds-mtxs          | 1.17.0                                        |
| @sap/eslint-plugin-cds | 2.6.7                                         |
| Node.js                | v18.18.0                                      |
| home                   | dch/crypto-for-business/node_modules/@sap/cds |

Repository Containing a Minimal Reproducible Example

https://github.tools.sap/erp4sme/crypto-for-business branch switch-to-cds-typer-payment-master-data aspect SourceReferences is defined here: db/masterData/common/SourceReferences.cds

Anything else?

No response

D027152 commented 2 months ago

Are there any comments on my problem?

daogrady commented 2 months ago

Hi Stefan,

sorry for the wait, I was OOO. I can confirm the problem you described. There appears to be some incorrect aspect naming going on (should be _SourceReferencesAspect, but is generated as _SourceReferencesAspect).

I will look into it.

Best, Daniel

daogrady commented 2 months ago

I have prepared a fix for this. Would you like to check if it works for your model before I release it?

D027152 commented 2 months ago

I would like to do so, but I am not sure what I have to do in order to link our repo to the feature branch of your repo. I assume this is possible, but I have never done this. If you tell me what I have to do I can give it a try.

daogrady commented 2 months ago

Sorry, I should have led with that! Please find this guide attached. If you need any further assistance in setting it up, just let me know.

D027152 commented 2 months ago

Thank you for the guide, I was able to follow the steps and hopefully did everything correctly.

Unfortunately, the correction seems not to work for me. The generated files look different, but still contain a syntax error.

See this example:

Before: image

With the correction from feature branch fix/singular-aspects image

daogrady commented 2 months ago

Could you please add the error message you are seeing there? Can you please also check @cds-models/sap/erp4sme/c4b/masterData/common/index.ts contains a export function _SourceReferenceAspect (singular! Not export function _SourceReferencesAspect plural). That appeared to be the problem that shold have been fixed.

D027152 commented 2 months ago

Hi Daniel

I just re-generated the files in @cds-models with the local link to your feature branch. I confirm that @cds-models/sap/erp4sme/c4b/masterData/common/index.ts contains an export function _SourceReferenceAspect (singular). There is no longer a syntax error in the file mentioned above (@cds-models/BusinessPartnerUiService/index.ts). I don't know why I did see different result yesterday. Anyway, your fix for this problem seems to work! Thank you.

I checked now all generated files in @cds-models for further syntax errors. Unfortunately, I found the following additional ones:

The error

Property 'Integration' in type '(Anonymous class)' is not assignable to the same property in base type '_cuidAspect<{ new (...args: any[]): _managedAspect<{ new (...args: any[]): _SourceReferenceAspect<TBase>.(Anonymous class); prototype: _SourceReferenceAspect<any>.(Anonymous class); readonly actions: Record<...>; } & TBase>.(Anonymous class); prototype: _managedAspect<...>.(Anonymous class); readonly actions: Record...'. Type 'string' has no properties in common with type 'Integration'.

occurs in the files

Several additional errors, like e.g.

Cannot redeclare exported variable '_PaymentAgreementOutgoingAspect'. Cannot redeclare exported variable '_PaymentAgreementIncomingAspect'. Class 'PaymentAgreementIncoming' used before its declaration.

occur in the file

I have pushed these in the branch switch-to-cds-typer-payment-master-data (see https://github.tools.sap/erp4sme/crypto-for-business/tree/switch-to-cds-typer-payment-master-data/%40cds-models)

Shall I open a separate bug for these, or can you check further in within this bug?

Thank you, Stefan

daogrady commented 2 months ago

Hi Stefan,

guess there was some caching or stale files going on, no worries. 🙂 I noticed these other errors as well and they look like a bigger problem. I would prefer to first get this PR in and push out a release asap and maybe attack this new issue in a follow up. So if you could just open a new issue for this other problem, that would be great!

Best, Daniel

D027152 commented 2 months ago

I created https://github.com/cap-js/cds-typer/issues/278 as follow-up for the new issues.