You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[typescript-angular] error TS1345: An expression of type 'void' cannot be tested for truthiness #8836
let formParams: { append(param: string, value: any): void; };
Steps to reproduce
Generate a new client with angular-typescript selected.
Reacted by Donatas Vizgirda, Giovanni Bertoncelli, Santiago Sanchez, Newton Zou, Clément, Matthieu Riegler, Peter Großmann, Florian Thuin, SimplyAboutCode, bitsmag and 2 more
Reacted by Marco Klein, SimplyAboutCode, Alain Kaiser and kien37
Same problem in our environment, after updating angular from v6 to v7 it is not possible to compile the genereated swagger services with the same error as seen above.
tried swagger-codegen-cli 2.4.0-SNAPSHOT and 3.0.2
Reacted by Sanket Berde, Cole Palm, briarHarrison and fireappsAdmin
@Dviejopomata , this actually has been implemented, you just need to pass the ngversion parameter while generating. The online generator is generating for angular 4.3 as a default.
@Dviejopomata , this actually has been implemented, you just need to pass the ngversion parameter while generating. The online generator is generating for angular 4.3 as a default.
do you have any pointers to what to set it? i tried with --additional-properties ngVersion=6.0.0 but that didn't seem to do anything.
I'm facing same problem, after I updating angular from v5 to v7. I used all version of swagger cli jars. I used following command to generate swagger code
Used command is java -jar ./swagger-codegen-cli-3.0.3.jar generate -i petstore.yaml -l typescript-angular -o ./local --additional-prop erties ngVersion=7.0.0
Same if I use ngVersion 7.1.0
Also all codegen-cli (jars) are generating invalid typescript 3 code. Errors are related to rxjs Imports and An expression of type 'void' cannot be tested for truthiness
Problematic code is
let formParams: { append(param: string, value: any): void; };
let useForm = false;
let convertFormParamsToString = false;
if (useForm) {
formParams = new FormData();
} else {
formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
}
if (name !== undefined) {
formParams = formParams.append('name', <any>name) || formParams;
}
if (status !== undefined) {
formParams = formParams.append('status', <any>status) || formParams;
}
useForm boolean is basically hardcoded and FormData constructor is never used.
formParams should be of this type and formParams=new FormData() line removed (i thinlk): let formParams: { append(param: string, value: any): HttpParams; };
@plathub This fix does not work because it is not only a typing issue, formParams.append could really return nothing or a new HttpParams with appended value.
I haven't found a valid workaround amongst the comments above... This problem appears also with openapi-generator every time an endpoint function has to use FormData or HttpParam. My solution was to define differently the formData variable so it can return void or something like a new HttpParam:
// HERE: if we use HttpParams the append function returns a new HttpParams object
// instead if we use FormData the append function will not return anything
let formParams: { append(param: string, value: any): void | HttpParams; };
let useForm = false;
let convertFormParamsToString = false;
if (useForm) {
formParams = new FormData();
} else {
formParams = new HttpParams({ encoder: new CustomHttpUrlEncodingCodec() });
}
if (newPassword !== undefined) {
// here there is no more the syntax error
formParams = formParams.append('newPassword', <any>newPassword) || formParams;
}
// here nothing changes
return this.httpClient.post<any>(`${this.basePath}/accounts/reset-password`,
convertFormParamsToString ? formParams.toString() : formParams,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
By using this everytime we use FormData/HttpParams the HTTP requests result valid.
Activity
artwel commentedon Oct 24, 2018
Same problem in our environment, after updating angular from v6 to v7 it is not possible to compile the genereated swagger services with the same error as seen above.
tried swagger-codegen-cli 2.4.0-SNAPSHOT and 3.0.2
Dviejopomata commentedon Oct 25, 2018
Also happens with
Which has to be :
As a workaround you can use some bash after generating the code
itsTeknas commentedon Oct 26, 2018
@Dviejopomata yeah this has been the case after updating the rxjs version to 6.0.0
itsTeknas commentedon Oct 29, 2018
@Dviejopomata , this actually has been implemented, you just need to pass the ngversion parameter while generating. The online generator is generating for angular 4.3 as a default.
awalland commentedon Oct 29, 2018
do you have any pointers to what to set it? i tried with
--additional-properties ngVersion=6.0.0but that didn't seem to do anything.Dviejopomata commentedon Oct 30, 2018
@awalland Make sure you are using v3.0.0 at least, i had to change from v2.3.1 to v3.0.0 and it worked fine:
Since i'm using docker this is what my command looks like:
jkarun commentedon Nov 12, 2018
I'm facing same problem, after I updating angular from v5 to v7. I used all version of swagger cli jars. I used following command to generate swagger code
java -jar ./swagger-codegen-cli-3.0.0-20180710.190537-87.jar generate -i http:///swagger/v1/swagger.json -l typescript-angular -o ./local --additional-properties ngVersion=7.0.0
TvrtkoM commentedon Dec 3, 2018
With swagger-codegen-cli-3.0.3.jar I get invalid petApi.service.ts
petApi.service.ts(364,1): error TS1005: '}' expected.Used command is
java -jar ./swagger-codegen-cli-3.0.3.jar generate -i petstore.yaml -l typescript-angular -o ./local --additional-prop erties ngVersion=7.0.0Same if I use ngVersion 7.1.0
Also all codegen-cli (jars) are generating invalid typescript 3 code. Errors are related to rxjs Imports and
An expression of type 'void' cannot be tested for truthinessProblematic code is
useForm boolean is basically hardcoded and FormData constructor is never used.
formParams should be of this type and formParams=new FormData() line removed (i thinlk):
let formParams: { append(param: string, value: any): HttpParams; };plathub commentedon Jan 3, 2019
Proposed fix: change the line
to
in the template file
api.service.mustachetilowestermann commentedon Jan 9, 2019
Is there any update on this issue (or the proposed PRs)?
[typescript-angular] error TS1345: An expression of type 'void' canno…
[typescript-angular] error TS1345: An expression of type 'void' canno…
[typescript-angular] error TS1345: An expression of type 'void' canno…
emmanuelgautier commentedon Jan 17, 2019
@plathub This fix does not work because it is not only a typing issue,
formParams.appendcould really return nothing or a new HttpParams with appended value.itsTeknas commentedon Apr 14, 2019
I have resorted to running my own
sanitise-swagger.shafter each generationThis does the corrections on all files under /src/swagger which is where i keep my generated client.
3 remaining items
gbertoncelli commentedon Jul 24, 2019
I haven't found a valid workaround amongst the comments above... This problem appears also with openapi-generator every time an endpoint function has to use FormData or HttpParam. My solution was to define differently the formData variable so it can return void or something like a new HttpParam:
By using this everytime we use FormData/HttpParams the HTTP requests result valid.
Hobart2967 commentedon Sep 21, 2019
Still valid for v3.0.11. Is this gonna be resolved any soon?
HugoMario commentedon Sep 21, 2019
hi @Hobart2967 , just assign it to myself, sadly i cant guarantee solve it soon, but once i have a chance i'll work on it
timdows commentedon Oct 1, 2019
Just like @itsTeknas I have used a script (powershell) to solve this for the time being
aaahrens commentedon Nov 16, 2019
any news on this?
JeanMeche commentedon Dec 17, 2019
I would love to see a fix too !
amenski commentedon Apr 19, 2020
As a temporary fix I used @itsTeknas solution on windows MinGw with a small dummy script launched on start up.
alainkaiser commentedon Jun 2, 2020
Any news on this? Still facing the same issue...
HugoMario commentedon Jul 16, 2020
this has been fixed by #9065 thanks everyone for help and sorry for delay.
de-don commentedon Aug 7, 2020
Still have this issue with
arraytype form-data parameters.Version - latest