Closed geert-janklaps closed 1 month ago
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
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
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.
Hi Christian,
thanks for adding the reproduction steps! I can now see the error and will look into it.
Best, Daniel
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
Hi @daogrady , thank you for providing a potential fix. How would I be able to test it ๐ ๐ ?
@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.
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
Is there an existing issue for this?
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.
The fix however is different, in the compilerOptions you need to disable useDefineForClassFields.
Expected Behavior
The generated types not to produce errors in strict mode
Steps To Reproduce
No response
Environment
Repository Containing a Minimal Reproducible Example
No response
Anything else?
No response