cds-typer
cds-typer copied to clipboard
[BUG] [REGRESSION] Extra class properties with incorrect types added
Is there an existing issue for this?
- [X] I have searched the existing issues
Nature of Your Project
TypeScript
Current Behavior
Let's say we have User
entity defined the following way:
export class User extends _._cuidAspect(_._managedAspect(_UserAspect(__.Entity))) {}
The class already inherits cuidAspect
and managedAspect
.
cuidAspect
defined as:
export function _cuidAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
return class cuid extends Base {
ID?: string | null;
static readonly actions: Record<never, never>
};
}
Now, for whatever reason cds-typer
decided to duplicate the inherited fields on the base class with different typing (ID?: string
vs ID?: string | null;
):
export function _UserAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
return class User extends Base {
ID?: string;
createdAt?: __.CdsTimestamp | null;
/**
* Canonical user ID
*/
createdBy?: _.User | null;
modifiedAt?: __.CdsTimestamp | null;
/**
* Canonical user ID
*/
modifiedBy?: _.User | null;
};
}
The duplicated fields appeared in the service
class definitions but not in the db schema
classes and because of this inconsistency I know get TS errors:
X [ERROR] NG2: Type 'import("models/gc/crm/index").User' is not assignable to type 'import("models/CrmService/index").User'.
Types of property 'ID' are incompatible.
Type 'string | null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.
Expected Behavior
No TS errors after cds-typer
update.
Steps To Reproduce
No response
Environment
- **OS**: Windows 10
- **Node**: 20.11.0
- **npm**:
- **cds-typer**: 0.20.1
- **cds**: 7.8.2
Repository Containing a Minimal Reproducible Example
No response
Anything else?
The last tested cds-typer
version without the TS errors: 0.16.0