An expression of type 'void' cannot be tested for truthiness#9012
An expression of type 'void' cannot be tested for truthiness#9012roni-frantchi wants to merge 9 commits intoswagger-api:masterfrom
Conversation
|
Hi Rony, What's outstanding for this PR? Cheers |
|
Hi @tengis . In the meantime I'm seeing yet another fix here #9065 by @marcbuils . |
| const canConsumeForm = this.canConsumeForm(consumes); | ||
|
|
||
| let formParams: { append(param: string, value: any): void; }; | ||
| let formParams: FormParams; |
There was a problem hiding this comment.
formParams could be a HttpParams type and need to not use the return as the same way.
There was a problem hiding this comment.
@emmanuelgautier FormParams type is defined here as a union type that includes HttpParams, so I think that would work. What am I missing?
What do you mean by "and need not use the return as the same way"?
There was a problem hiding this comment.
FormData and HttpParams append function does not have the same signature :
One return FormParams and the other not. When you use formParams.append, you have to check what is the exact variable type. Here, you do not make this check and could be a potential error when formParams is a HttpParams and you use HttpClient
It is almost the same thing that I done in this lines.
There was a problem hiding this comment.
@emmanuelgautier: They differ on the return type, that is the reason why in my method, I implicitly check the type (by checking the useReturnValue ) -
If it's HttpParams I return the return value of append(), if it isn't, I append, and return the same instance (see the comma , there).
There was a problem hiding this comment.
Here, if you use HttpClient, you do not use useReturnValue but formParams could be a HttpParams and return value.
|
is there any news? Probably it was fixed in here OpenAPITools/openapi-generator@0a45890#diff-f61af8a4c4eb2720bfb15259e0dca419 |
Closes #8968 .
See PR by @navneetkarnani for more details and trial.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/typescript-angular-all-petstore.shand./bin/security/{LANG}-petstore.sh.3.0.0branch for changes related to OpenAPI spec 3.0. Default:master.Description of the PR
The Typescript 3.1 compiler (one that is used with Angular 7 onwards), has a check for void functions being checked for Truthiness.
This change drops the or (
||) operator altogether, extracts the assignment code to runtime and utilizes the comma (,) operator instead.