swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

header in baseApiParams has wrong type in Typescript

Open yuzhouu opened this issue 1 year ago • 0 comments

https://github.com/acacode/swagger-typescript-api/blob/2b6db2346028fe6fb1f311bf5b1221a89837032e/templates/base/http-clients/fetch-http-client.ejs#L123-L130

according to typescript, baseApiParams.header is shape of HeaderInit. and type HeadersInit = [string, string][] | Record<string, string> | Headers;

and header is expand in the code above,

  • expand Headers instance will result to {}
  • expand [string, string][] will result to {0: [string, string]}

only Record<string, string> will work as expected

we need to narrow baseApiRarams.header's type to Record<string, string> in type RequestParams

yuzhouu avatar Mar 24 '24 05:03 yuzhouu