-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[typescript-angular] error TS1345: An expression of type 'void' cannot be tested for truthiness #8836
Comments
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. |
Also happens with
Which has to be :
As a workaround you can use some bash after generating the code sed -i 's/rxjs\/Observable/rxjs/' ./src/app/swagger/api/api.service.ts
sed -i 's/formParams = formParams/formParams/' ./src/app/swagger/api/api.service.ts
sed -i 's/ || formParams//' ./src/app/swagger/api/api.service.ts |
@Dviejopomata yeah this has been the case after updating the rxjs version to 6.0.0 |
@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 |
@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:
|
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 |
With swagger-codegen-cli-3.0.3.jar I get invalid petApi.service.ts
Used command is 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 Problematic code is
useForm boolean is basically hardcoded and FormData constructor is never used. |
Proposed fix: change the line
to
in the template file |
Is there any update on this issue (or the proposed PRs)? |
…t be tested for truthiness swagger-api#8836
…t be tested for truthiness swagger-api#8836
…t be tested for truthiness swagger-api#8836
@plathub This fix does not work because it is not only a typing issue, |
I have resorted to running my own
This does the corrections on all files under /src/swagger which is where i keep my generated client. |
@emmanuelgautier Can we not have a builder wraps around FormData that supports the same append signature ? Something similar to the below.
|
@sohoffice Creating a class just for one use case seem a bit over engineered IMHO. I prefer a simple function. This MR fix the issue with the same method : #9012 |
@emmanuelgautier #9012 seems to be failing on angular v4, is there anything I can do to get it merged ? |
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. |
Still valid for v3.0.11. Is this gonna be resolved any soon? |
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 |
Just like @itsTeknas I have used a script (powershell) to solve this for the time being java -jar .\swagger-codegen-cli-2.4.1.jar generate -i http://localhost:5100/swagger/v1/swagger.json -l typescript-angular -o ../src/api
$file = '..\src\api\api\thexyz.service.ts'
$find = 'let formParams: { append(param: string, value: any): void; };'
$replace = 'let formParams: { append(param: string, value: any): void | HttpParams; };'
(Get-Content $file).replace($find, $replace) | Set-Content $file |
any news on this? |
I would love to see a fix too ! |
As a temporary fix I used @itsTeknas solution on windows MinGw with a small dummy script launched on start up.
|
Any news on this? Still facing the same issue... |
this has been fixed by #9065 thanks everyone for help and sorry for delay. |
Still have this issue with |
Description
The generated typescript client fails in angular 7 build when there seems to be any sort of file field.
Typescript version
"typescript": "^3.1.3"
Swagger-codegen version
The latest online version
Swagger declaration file content or url
Produces:
The definition of append tracks down to
Steps to reproduce
Generate a new client with angular-typescript selected.
The text was updated successfully, but these errors were encountered: