Skip to content

[BUG][typescript-fetch] HTTPHeaders and RequestCredentials type errors #3604

Closed
@gbark

Description

@gbark

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
    4.1.0
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?

Expected:
No type errors in TypeScript output.

Actual:

src/api/petstore/src/runtime.ts:186:9 - error TS2322: Type 'HTTPHeaders | undefined' is not assignable to type 'HTTPHeaders'.
  Type 'undefined' is not assignable to type 'HTTPHeaders'.

186         return this.configuration.headers;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/api/petstore/src/runtime.ts:190:9 - error TS2322: Type '"omit" | "same-origin" | "include" | undefined' is not assignable to type 'RequestCredentials'.
  Type 'undefined' is not assignable to type 'RequestCredentials'.

190         return this.configuration.credentials;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Description

A type error regression was introduced with this PR. The return types of get headers() and get credentials() in runtime.ts doesn't reflect that the return value might be undefined.

openapi-generator version

4.1.0

OpenAPI declaration file content or url

https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml

Steps to reproduce
  1. Generate typescript-fetch API client: openapi-generator generate -g typescript-fetch -i ./PATH_TO_PETSTORE.yml -o ./petstore
  2. Typecheck code: tsc ./petstore --noEmit
  3. See error in Typescript compiler output

OR:

Clone this repo and run npm install && npm run typecheck:
https://github.com/gbark/openapi-petstore

Suggest a fix

Adding undefined as a return type to get headers() and get credentials() in runtime.ts should do it.

I've created a small PR which fixes it. #3605

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions