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] TS4114 error introduced in v0.23.0 #273

Closed
1 task done
hakimio opened this issue Jul 8, 2024 · 20 comments · Fixed by #283 or #367
Closed
1 task done

[BUG][REGRESSION] TS4114 error introduced in v0.23.0 #273

hakimio opened this issue Jul 8, 2024 · 20 comments · Fixed by #283 or #367
Assignees
Labels
bug Something isn't working new

Comments

@hakimio
Copy link

hakimio commented Jul 8, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Nature of Your Project

TypeScript

Current Behavior

Transpiling code produced by v0.23.0 of cds-typer produces error:

X [ERROR] TS4114: This member must have an 'override' modifier because it overrides a member in the base class '_cuidAspect<{ new (...args: any[]): _managedAspect<{ new (...args: any[]): _oldCrmIdAspect<TBase>.(Anonymous class); prototype: _oldCrmIdAspect<any>.(Anonymous class); readonly actions: Record<...>; } & TBase>.(Anonymous class); prototype: _managedAspect<...>.(Anonymous class); readonly actions: Record<...>; } & { ....'. 

    ../models/CrmService/index.ts:9:8:
      9 │         ID?: string;
        ╵         ~~

Expected Behavior

No errors.

Steps To Reproduce

  1. Add entity with some aspects:
entity Foo : cuid, managed {}
  1. Generate the types
  2. Try to transpile the TS code

Environment

- **OS**: Windows 10
- **Node**: 20.13.1
- **npm**: 10.8.1
- **cds-typer**: 0.23.0
- **cds**: 7.9.3

Repository Containing a Minimal Reproducible Example

No response

Anything else?

noImplicitOverride tsconfig config is set to true.

@hakimio hakimio added bug Something isn't working new labels Jul 8, 2024
@hakimio hakimio changed the title [BUG][REGRESSION] TS4114 error introduced in v0.23.0 [BUG][REGRESSION] TS4114 error introduced in v0.23.0 Jul 8, 2024
@daogrady
Copy link
Contributor

daogrady commented Jul 8, 2024

Hi Tomas,

thanks for reporting this problem! As you have correctly deduced, this problem is directly related to the noImplicitOverride configuration. One layover solution would be to set noImplicitOverride to false.
I fully understand (and support) that you want to make your config as strict as possible.
I'd first have to evaluate whether just slapping override (and declare) on every property has any implications. It is currently a non-trivial issue to determine whether a property already exists in a parent aspect/ entity.

So for now, I recommend removing the noImplicitOverride option is possible. Resolving this issue needs a bit of digging.

Best,
Daniel

@hakimio
Copy link
Author

hakimio commented Jul 8, 2024

Ok, for now I can disable noImplicitOverride but in the future the issue should definitely be addressed.

Anyway, another reason why I don't like the new v0.23.0 release is that it messes up the type tooltips in the IDE.

Here is how it looked like before in v0.22.0:

image

And here is how it looks like now in v0.23.0:

image

Really ugly.

@daogrady
Copy link
Contributor

daogrady commented Jul 8, 2024

The latter issue probably stems from me removing the names of the classes generated by the class aspects. Your IDE looks a bit different from mine, but could you please open the generated types and give the class in question a name?
It should look something like this:

export function _UserAspect_<TBase extends new (...args: any[]) => object>(Base: TBase) {
  return class /* add "User" in here */ extends Base { ... };
}
export class User extends _UserAspect(__.Entity) {}

and let me know if adding the name back in prettifies the tooltip.

@hakimio
Copy link
Author

hakimio commented Jul 8, 2024

Yes, it does fix the IDE tooltip.
I am using JetBrains WebStorm instead of VS Code.

@daogrady
Copy link
Contributor

daogrady commented Jul 8, 2024

alright, that is good to know. I wanted to make the generated types a bit leaner and wasn't aware of the effect this would have. I will thus revert that particular change. Thanks for pointing it out.

@dragolea
Copy link

hi @daogrady
Will this be fixed in a newer version ?
tsc now throws an error:

error TS2416: Property 'ID' in type '(Anonymous class)' is not assignable to the same property in base type '_managedAspect<{ new (...args: any[]): _cuidAspect<TBase>.(Anonymous class); prototype: _cuidAspect<any>.(Anonymous class); readonly actions: Record<...>; } & TBase>.(Anonymous class) & _cuidAspect<...>.(Anonymous class) & object'.
  Type 'number | undefined' is not assignable to type 'string | undefined'.

226         ID?: number;
            ~~

version 0.22.0 works as expected.

@hakimio
Copy link
Author

hakimio commented Jul 11, 2024

@dragolea
Might be an issue that your entity looks like the following:

entity Entities: cuid, managed {
    key ID: Integer;
}

cuid aspect sets ID to string and then you redefine it as integer again.

@dragolea
Copy link

@hakimio
Thanks for the tip, like always.

@hakimio
Copy link
Author

hakimio commented Jul 11, 2024

Is it a good tip? 🙂

@dragolea
Copy link

yep, fixed the issue

@daogrady
Copy link
Contributor

Hi @hakimio ,

I have prepared a fix that was originally meant to address a related problem. But when toying around with it, it looked like it could also be a fix for your issue. Would you mind trying it out to see if all your cases are addressed or it it needs additional work?

Best,
Daniel

@hakimio
Copy link
Author

hakimio commented Aug 5, 2024

Hi @daogrady

The issue is almost fixed. Now I'm only getting the errors for actions property:

image

TS4114: This member must have an 'override' modifier because it overrides a member in the base class '_CodeListAspect<TBase>.CodeList & object'.

    ../models/sap/common/index.ts:71:22:
      71 │       static readonly actions: Record<never, never>
         ╵                       ~~~~~~~

@daogrady
Copy link
Contributor

daogrady commented Aug 5, 2024

🤔 that is actually bad news, as we don't want to override in this case, but add to the type. I will have to investigate a bit more on this. Thanks for the feedback!

@daogrady
Copy link
Contributor

daogrady commented Aug 6, 2024

Hi @hakimio,

I have extended the approach in the PR to handle the actions property as well. Would you mind checking again?

Best,
Daniel

@hakimio
Copy link
Author

hakimio commented Aug 7, 2024

Hi @daogrady

While you have resolved the actions combination issue, declare is still required in front of actions like you've added for other properties. Right now I am getting the same error as before.

@daogrady
Copy link
Contributor

daogrady commented Aug 7, 2024

Hi Tomas,

thanks for checking! I am a bit unclear on the situation. The current state in the PR I linked should generate the declare modifier for actions. Is that not the case?

Best,
Daniel

@daogrady
Copy link
Contributor

daogrady commented Aug 7, 2024

Ah, I see the problem. That's what you get from code duplication. Should be fixed. 🙂

@hakimio
Copy link
Author

hakimio commented Aug 7, 2024

Seems to be working well now 🙂

@hakimio
Copy link
Author

hakimio commented Sep 18, 2024

@daogrady the issue has been reintroduced in 0.26.0:

X [ERROR] TS4114: This member must have an 'override' modifier because it overrides a member in the base class '_CodeListAspect<TBase>.CodeList & object'. [plugin angular-compiler]

    ../models/sap/common/index.ts:105:22:
      105 │       static readonly kind: 'entity' | 'type' | 'aspect' = 'entity';

@daogrady
Copy link
Contributor

Hi Tomas,

thanks for pointing this out. This will actually be a bit more complicated to fix as this introduces two diametral requirements. I will look into it, but it could take a while.

Best,
Daniel

@daogrady daogrady self-assigned this Sep 18, 2024
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
3 participants