-
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
An expression of type 'void' cannot be tested for truthiness #9012
base: master
Are you sure you want to change the base?
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 . |
@@ -262,7 +262,8 @@ export class {{classname}} { | |||
{{#hasFormParams}} | |||
const canConsumeForm = this.canConsumeForm(consumes); | |||
|
|||
let formParams: { append(param: string, value: any): void; }; | |||
let formParams: FormParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formParams could be a HttpParams
type and need to not use the return as the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, if you use HttpClient, you do not use useReturnValue
but formParams could be a HttpParams
and return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. My bad 👍
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.sh
and./bin/security/{LANG}-petstore.sh
.3.0.0
branch 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.