NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

This member must have an 'override' modifier because it overrides a member in the base class 'Error'.

Open ranouf opened this issue 2 years ago • 15 comments

Hi,

When I generate the Typescript Api Services from a C# API, I have an issue with Exception class generated by NswagStudio:

export class ApiException extends Error {
    message: string; //here is the error
    status: number;
    response: string;
    headers: { [key: string]: any; };
    result: any;

    constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
        super();

        this.message = message;
        this.status = status;
        this.response = response;
        this.headers = headers;
        this.result = result;
    }

    protected isApiException = true;

    static isApiException(obj: any): obj is ApiException {
        return obj.isApiException === true;
    }
}

Here is my configuration in NswagStudio for the exception image Version: image

And the error :

Error: src/app/services/api/api.services.ts:1915:5 - error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Error'.

1915 message: string; ~~~~~~~

I can't see any option about that in nswag studio. As the file is automatically generated, I would like to avoid to modifiy the typescript api services files each time the file is updated.

Is there a specific option to fix the issue?

Thanks

ranouf avatar May 12 '22 15:05 ranouf

What's your TS version in nswag.json?

lahma avatar May 12 '22 17:05 lahma

The issue is already known since novembre 2021. => https://github.com/RicoSuter/NSwag/issues/3685

Here, many people are waiting for it resolution.

lilletech avatar May 13 '22 07:05 lilletech

You need to use "typeScriptVersion": 4.3 in your nswag configuration for the override keyword to be generated.

ovska avatar May 13 '22 08:05 ovska

@ovska which version do you use ? image

lilletech avatar May 13 '22 10:05 lilletech

I have the same version, and 4.3 shows up on the dropdown (don't mind the Win95 look; I'm using it through Wine). image image

Try downloading the latest release as zip, and using the NSwagStudio.exe inside. I've had some problems with the msi builds lately.

ovska avatar May 13 '22 12:05 ovska

@ovska yes, portable version shows the 4.3 typescript version. (Not the msi).

lilletech avatar Jun 02 '22 10:06 lilletech

Thanks that was the solution

ranouf avatar Jul 04 '22 16:07 ranouf

@lilletech @ranouf

Hi! Our nswag.json also uses 4.3 as the typescript version, but override is still not generated for the message.

Does your generated typescript client include the override keyword? If so, could you post your nswag.json so I can compare?

sander1095 avatar Sep 08 '22 10:09 sander1095

Hi @sander1095 , we managed to fix this issue by upgrading the NSwag packages from version 13.14.8 to 13.15.10.

joerygrolleman avatar Sep 09 '22 08:09 joerygrolleman

Yeah the override is being added for errors as seen here: https://github.com/RicoSuter/NSwag/blob/4749251c712d90ff906251e23f8044031993c934/src/NSwag.CodeGeneration.TypeScript/Templates/File.liquid#L129

but it's not being added for classes that extend from base classes. At least not in version 13.17.0.

TomONeill avatar Oct 26 '22 15:10 TomONeill

This is still broken.

What is the fix? (My pakcage.json says "tslib": "^2.3.0" so all this talk about a version 4 seems odd.)

rwb196884 avatar Jan 23 '23 12:01 rwb196884

In my travels I've landed here thought I'd help out if possible...

I noticed that public does not cause TS to give this error. private was.

BenRacicot avatar Feb 09 '23 12:02 BenRacicot

I have same issue while using ProblemDetails. My project's typescript version is 4.9.5 and in nswag studio It's 4.3. Is there any fix or solution for it?

mossykazemi avatar Jul 31 '23 10:07 mossykazemi

Same issue as @ranouf

nswag@npm:14.0.3
"typeScriptVersion": 5.0

maxbechtold avatar Feb 16 '24 15:02 maxbechtold