Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Imports for references #48

Open
CedricSchreiner opened this issue Jan 13, 2023 · 1 comment
Open

Missing Imports for references #48

CedricSchreiner opened this issue Jan 13, 2023 · 1 comment

Comments

@CedricSchreiner
Copy link

Version used: 3.0.0
CDS Version: 6.3.2

As an example we have two different CDS files which have a reference to each other. If you now execute cds2types, the corresponding files are generated, however, they are currently incorrect because each is missing in import.

Here a simple Example:

BusinessTransactionPayload:

using {
  managed,
  cuid,
} from '@sap/cds/common';
using {entities.message.TransferDocument} from './transfer-document';

namespace entities.shadow;

entity BusinessTransactionPayload : managed {
  key uuid                        : UUID;
      transferDocumentUUID        : UUID;
      transferDocument            : Association to one TransferDocument
                                      on transferDocument.uuid = $self.transferDocumentUUID;
}

TransferDcoument

using {
  managed,
  cuid,
} from '@sap/cds/common';
using {entities.shadow.BusinessTransactionPayload} from './business-transaction';


namespace entities.message;

entity TransferDocument : managed {
  key uuid                                      : UUID;
      toBusinessTransaction                     : Composition of many BusinessTransactionPayload
                                                    on toBusinessTransaction.transferDocumentUUID = $self.uuid;
}

Compiles to

export interface IBusinessTransactionPayload {
  uuid: string;
  transferDocumentUUID: string;
  transferDocument?: entities.message.ITransferDocument;
}
export interface ITransferDocument {
  uuid: string;
  toBusinessTransaction: entities.shadow.IBusinessTransactionPayload[];
}

The problem here is that the generated Typescript file can not find the reference to entities.message.ITransferDocument or entities.shadow.IBusinessTransactionPayload because these are both in separate generated files. When a import is manually added its working. Is this behavior intended?

Kind Regards

@netux
Copy link

netux commented May 18, 2023

+1. I investigated further and the import is actually added at one point, but is then removed during the formatting step because it isn't being used.

The problem really is that the type of the field is spelled out with the namespace before it (e.g. entities.message.ITransferDocument instead of just ITransferDocument) (as defined here).
But the import is done in the format import { ... entities ... } from './{full namespace}' (here)

The formatter doesn't care about invalid types, so it doesn't throw an error. It just silently does its job of removing (technically) unused imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants