Skip to content

Commit 6a805ba

Browse files
test(openapi-fetch): use Headers.forEach in headersToObj to drop ts-expect-error lib workaround
Suggested by @LMBernardo in #2774 review.
1 parent 757893c commit 6a805ba

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

packages/openapi-fetch/test/helpers.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export function createObservedClient<T extends {}, M extends MediaType = MediaTy
2424
}
2525

2626
/**
27-
* Convert a Headers object to a plain object for easier comparison
27+
* Convert a Headers object to a plain object for easier comparison.
28+
* Uses Headers.forEach rather than Headers.entries because forEach is in base
29+
* lib.dom with an identical signature in both TS 5.x and 6.x, while entries
30+
* requires DOM.Iterable in TS 5.x.
2831
*/
2932
export function headersToObj(headers: Headers | Record<string, string>): Record<string, string> {
30-
const iter =
31-
headers instanceof Headers
32-
? headers
33-
// @ts-expect-error FIXME: this is a missing "lib" in tsconfig.json but dunno what
34-
.entries()
35-
: Object.entries(headers);
36-
const result: Record<string, string> = {};
37-
for (const [k, v] of iter) {
38-
result[k] = v;
33+
if (!(headers instanceof Headers)) {
34+
return { ...headers };
3935
}
36+
const result: Record<string, string> = {};
37+
headers.forEach((value, key) => {
38+
result[key] = value;
39+
});
4040
return result;
4141
}

0 commit comments

Comments
 (0)