Skip to content

[BUG][ANGULAR] Typescript compiler error when using formData #2147

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

Closed
rolandbaettig opened this issue Feb 13, 2019 · 1 comment · Fixed by #2149
Closed

[BUG][ANGULAR] Typescript compiler error when using formData #2147

rolandbaettig opened this issue Feb 13, 2019 · 1 comment · Fixed by #2149

Comments

@rolandbaettig
Copy link

Description

Following api-definition leads to a typscript compiler error

  /document/upload:
    post:
      tags:
        - document
      summary: 'uploads a pdf as a document'
      consumes:
        - multipart/form-data
      parameters:
        - in: formData
          name: file
          type: file
          description: 'The file to upload.'
      responses:
        200:
          description: 'Successful operation'

this generates in the angular service following code (snippet):

        if (file !== undefined) {
            formParams = formParams.append('file', <any>file) || formParams;
        }

which leads to following typscript error:

ERROR in src/app/core/services/backend-api/generated/api/document.service.ts(447,26): error TS1345: An expression of type 'void' cannot be tested for truthiness

openapi-generator version

3.3.4

OpenAPI declaration file content or url
  /document/upload:
    post:
      tags:
        - document
      summary: 'uploads a pdf as a document'
      consumes:
        - multipart/form-data
      parameters:
        - in: formData
          name: file
          type: file
          description: 'The file to upload.'
      responses:
        200:
          description: 'Successful operation'
        405:
          description: 'Invalid input'
Command line used for generation

maven-plugin

Suggest a fix
        if (file !== undefined) {
            formParams = formParams.append('file', <any>file) as any || formParams;
        }
wing328 pushed a commit that referenced this issue Feb 14, 2019
* #2147: fix compiler error in angular typescript codegen

* #2147: generate samples
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this issue Feb 27, 2019
@macjohnny
Copy link
Member

this is due to microsoft/TypeScript#26262, a breaking change in typescript 3.1
I can't find a way to tell the compiler to ignore this error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants