NSwag
NSwag copied to clipboard
This member must have an 'override' modifier because it overrides a member in the base class 'Error'.
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
Version:
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
What's your TS version in nswag.json?
The issue is already known since novembre 2021. => https://github.com/RicoSuter/NSwag/issues/3685
Here, many people are waiting for it resolution.
You need to use "typeScriptVersion": 4.3
in your nswag configuration for the override
keyword to be generated.
@ovska which version do you use ?
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).
Try downloading the latest release as zip, and using the NSwagStudio.exe inside. I've had some problems with the msi builds lately.
@ovska yes, portable version shows the 4.3 typescript version. (Not the msi).
Thanks that was the solution
@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?
Hi @sander1095 , we managed to fix this issue by upgrading the NSwag packages from version 13.14.8 to 13.15.10.
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.
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.)
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.
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?
Same issue as @ranouf
nswag@npm:14.0.3
"typeScriptVersion": 5.0