fetch http client return type is wrong when `unwrapResponseData` is false

Open Beginner friendly
#513 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
api, tooling

Research direction

Examine the fetch-http-client.ejs template file around lines 159-224. Understand how the unwrapResponseData flag affects the generated TypeScript return type. The fix involves updating the template to return Promise<HttpResponse<T, null>> when the flag is false. Test by generating a client with a sample OpenAPI spec to verify the corrected type.

Written by the indexing model from the issue text.

Description

Looking at this code: https://github.com/acacode/swagger-typescript-api/blob/master/templates/base/http-clients/fetch-http-client.ejs#L159-L224

The return type should be Promise<HttpResponse<T, null>> when unwrapResponseData is false. If the request is successful and no error is thrown, the error property will always be null.

In fact, it seems like there is no point in having the generic E as a part of custom fetch because there is no guarantee that it will be the type given this line https://github.com/acacode/swagger-typescript-api/blob/master/templates/base/http-clients/fetch-http-client.ejs#L206.

Dominant language
TypeScript
Stars
4.1k
Forks
436
Avg merge
9d 7h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from acacode/swagger-typescript-api

All issues in acacode/swagger-typescript-api

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.