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

[BUG] [REGRESSION] TS2612 - Property 'ID' will overwrite the base property in '_cuidAspect<TBase> (v0.23.0) #274

Closed
1 task done
geert-janklaps opened this issue Jul 16, 2024 · 9 comments · Fixed by #283
Labels
bug Something isn't working new

Comments

@geert-janklaps
Copy link

geert-janklaps commented Jul 16, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Nature of Your Project

TypeScript

Current Behavior

As of release v0.23.0 generated types using cuidAspect produce TS2612 errors. (strict tsconfig)
This issue might be closely related to #273.
image

The fix however is different, in the compilerOptions you need to disable useDefineForClassFields.

{
  "ts-node": {
    "files": true
  },
  "compilerOptions": {
    "paths": {
      "#cds-models/*": [
        "./@cds-models/*"
      ]
    },
    "rootDir": "./",
    "target": "ESNext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "sourceMap": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": false,
    "skipLibCheck": true,
    "useDefineForClassFields": false
  }
}

Expected Behavior

The generated types not to produce errors in strict mode

Steps To Reproduce

No response

Environment

@cap-js/asyncapi: 1.0.1
@cap-js/cds-typer: 0.23.0
@cap-js/openapi: 1.0.4
@cap-js/sqlite: 1.7.3
@sap/cds: 7.9.3
@sap/cds-common-content: 1.4.0
@sap/cds-compiler: 4.9.6
@sap/cds-dk: 7.9.5
@sap/cds-dk (global): 8.0.2
@sap/cds-fiori: 1.2.7
@sap/cds-foss: 5.0.1
@sap/cds-hana: 2.0.0
@sap/cds-mtxs: 1.18.2
@sap/eslint-plugin-cds: 2.7.0
Node.js: v20.14.0

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

@geert-janklaps geert-janklaps added bug Something isn't working new labels Jul 16, 2024
@cpf-hse
Copy link

cpf-hse commented Jul 24, 2024

Thank you @geert-janklaps for the mentioned fix.
Had the same issue:
error TS2612: Property 'createdAt' will overwrite the base property in '_managedAspect<TBase>.managed & object'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.

@cap-js/asyncapi: 1.0.2
@cap-js/cds-typer: 0.24.0
@cap-js/cds-types: 0.6.3
@cap-js/openapi: 1.0.4
@cap-js/postgres: 1.9.1
@cap-js/sqlite: 1.7.3
@sap/cds: 8.0.4
@sap/cds-compiler: 5.0.6
@sap/cds-dk (global): 8.0.3
@sap/cds-fiori: 1.2.7
@sap/cds-foss: 5.0.1
@sap/cds-mtxs: 2.0.3
@sap/eslint-plugin-cds: 3.0.4
Node.js: v20.15.1

@daogrady
Copy link
Contributor

daogrady commented Jul 25, 2024

Hi Geert-Jan,

thanks for reporting this issue!
I am unable to reproduce the problem with the information I have so far.

With the following tsconfig.json:

{
"compilerOptions": {
  "paths": {
    "#cds-models/*": [
      "./@cds-models/*"
    ]
  },
  "rootDir": "./",
  "target": "ESNext",
  "module": "NodeNext",
  "moduleResolution": "NodeNext",
  "sourceMap": true,
  "esModuleInterop": true,
  "forceConsistentCasingInFileNames": true,
  "strict": true,
  "noImplicitOverride": false,
  "skipLibCheck": true,
  "useDefineForClassFields": true
}
}

and this minimal model:

using { cuid } from '@sap/cds/common';
namespace my.bookshop;

entity Book: cuid {
    key ID : Integer;
    title : String;
    author : String;
    stock : Integer;
    price : Decimal(9,2);
}

I am running tsc (5.5.4) in my project root and I do not see any errors and the transpiler emits .js files just fine.

Could you please expand your sample with a minimal model I can reproduce the issue with? Thanks!

Best,
Daniel

@cpf-hse
Copy link

cpf-hse commented Jul 25, 2024

I can support here as well as I also had this issue.

Steps to reproduce

cds init typerbug
cds add typescript
npm install

The generated tsconfig file provided by CAP looks like this

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "allowJs": true,
    "paths": {
      "#cds-models/*": [
        "./@cds-models/*/index.ts"
      ]
    }
  }
}

Now add the following schema.cds to your db folder

using {managed} from '@sap/cds/common';

namespace typer.bug;

entity ManagedEntity : managed {
    key id        : UUID;
        something : String(15);
}

Now create a service.cds in the srv folder

using {typer.bug as service} from '../db/schema';

service ManagedService {
    entity ManagedEntity as projection on service.ManagedEntity;
}

Run build

cds-ts build

Output

Error: @cds-models/ManagedService/index.ts(7,5): error TS2612: Property 'createdAt' will overwrite the base property in '_managedAspect<TBase>.managed & object'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
@cds-models/ManagedService/index.ts(11,5): error TS2612: Property 'createdBy' will overwrite the base property in '_managedAspect<TBase>.managed & object'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
@cds-models/ManagedService/index.ts(12,5): error TS2612: Property 'modifiedAt' will overwrite the base property in '_managedAspect<TBase>.managed & object'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
@cds-models/ManagedService/index.ts(16,5): error TS2612: Property 'modifiedBy' will overwrite the base property in '_managedAspect<TBase>.managed & object'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.

@daogrady
Copy link
Contributor

Hi Christian,

thanks for adding the reproduction steps! I can now see the error and will look into it.

Best,
Daniel

@daogrady
Copy link
Contributor

Hi everyone,

I have prepared an experimental fix for this issue that will add the declare modifier to all properties.
Would you mind trying out this proposal to see if it matches your use case and works in combination with your tsconfig.json?

Best,
Daniel

@cpf-hse
Copy link

cpf-hse commented Jul 29, 2024

Hi @daogrady ,
thank you for providing a potential fix.
How would I be able to test it 😓 😄 ?

@daogrady
Copy link
Contributor

Hi Christian,

sorry, I forgot to attach the relevant wiki page.

Best,
Daniel

@cpf-hse
Copy link

cpf-hse commented Jul 31, 2024

@daogrady I try to do it this week.
I had a covid infection and was not able to work until today. I do by best to test it by the end of this week.

@daogrady
Copy link
Contributor

daogrady commented Aug 7, 2024

Hi Christian,

sorry to hear and hope you recover quickly! 😕 I have merged the fix in question for a related problem. So I will for now assume the problem is fixed (with the next release). If you notice the problem resurfacing, feel free to reopen this issue.

Best,
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants