NSwag: Tons of errors after upgrading to the latest version of Nswag Studio
Hi!
I’ve got tons of errors after upgrading Nswag Studio. How can I fix it? How can I downgrade or if anyone has the link of the previous version of NSwag Studio?
this is one of the functions generated by NSWAG:
return _observableOf<AddOrEditUserResponseVM>(<any[]>null);
before it was:
return _observableOf<boolean>(<any>null);
Im trying to generate Typescript client code from c#
Error:
{
"resource": "/c:/Users/admin/source/repos/TaskApp/ClientApp/src/app/swagger-generated.ts",
"owner": "typescript",
"code": "2769",
"severity": 8,
"message": "No overload matches this call.\n Overload 1 of 20, '(...args: (SchedulerLike | AddOrEditUserResponseVM)[]): Observable<AddOrEditUserResponseVM>', gave the following error.\n Argument of type 'any[]' is not assignable to parameter of type 'SchedulerLike | AddOrEditUserResponseVM'.\n Type 'any[]' is missing the following properties from type 'AddOrEditUserResponseVM': init, toJSON, clone\n Overload 2 of 20, '(a: AddOrEditUserResponseVM): Observable<AddOrEditUserResponseVM>', gave the following error.\n Argument of type 'any[]' is not assignable to parameter of type 'AddOrEditUserResponseVM'.\n Overload 3 of 20, '(...args: AddOrEditUserResponseVM[]): Observable<AddOrEditUserResponseVM>', gave the following error.\n Argument of type 'any[]' is not assignable to parameter of type 'AddOrEditUserResponseVM'.",
"source": "ts",
"startLineNumber": 142,
"startColumn": 55,
"endLineNumber": 142,
"endColumn": 66
}

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 15 (5 by maintainers)
I don’t think this was properly fixed, since the errors I get with version 13.12.1.0 are very similar. Upgrading and simply generating the Angular TypeScript files now changes
return _observableOf<T>(<any>null);toreturn _observableOf(null);for a method that has a return type ofObservable<T>. This generates the following error:Note that this error should only occur when
strictNullChecksis set totruefor the TypeScript compiler. This setsnullandundefinedas separate types instead of adding it implicitly to every type.For it to work with that strict flag enabled, the return type should be
Observable<T | null>.Type errors aside, I also don’t think the behavior is entirely correct. If you take the process method (see below) the
return _observableOf(null)statement is actually undefined behavior and should not return anullvalue, but rather throw an error. When any status code is encoutered that was not defined, it should go throughreturn throwException(...)I feel. There might be some extra code to handle the 204 response (which was not defined, so I don’t think it belongs here since we are also now adding| nullto the contract which isn’t necessarily the case), but the lastelse ifstatement should just be anelsestatement so the last return statement can be removed.Original code
Proposed code
Fixed in v13.12.1
I’m not sure if the project qualifies for a “bigger project”, it’s got around 15k lines in the generated client after formatting with Prettier.
I’ve just tested it, and everything seems to work for me.
See https://github.com/RicoSuter/NSwag/issues/3566
For your question about downgrading, you can find all the versions in the github releases of this repo.