From c3c9bb601197021e086bd3cc0ba17a1fa80de1cc Mon Sep 17 00:00:00 2001 From: Mikkel RINGAUD Date: Mon, 1 Jul 2024 22:31:00 +0200 Subject: [PATCH] fix(headers): types --- src/utils/headers.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/headers.ts b/src/utils/headers.ts index 4e3decd..09bcfa3 100644 --- a/src/utils/headers.ts +++ b/src/utils/headers.ts @@ -1,6 +1,10 @@ import cookieParser from "set-cookie-parser"; -export const retrieveResponseCookies = (headers: Record | Headers): string[] => { +interface HeadersLike { + get (key: string): string | null +}; + +export const retrieveResponseCookies = (headers: Record | Headers | HeadersLike): string[] => { const setCookieHeader = getHeaderFromFetcherResponse(headers, "set-cookie"); if (setCookieHeader === null) return []; @@ -10,6 +14,8 @@ export const retrieveResponseCookies = (headers: Record | Header return cookies; }; -export const getHeaderFromFetcherResponse = (headers: Record | Headers, item: string): string | null => { - return (typeof headers.get === "function") ? headers.get(item) : headers[item]; +export const getHeaderFromFetcherResponse = (headers: Record | Headers | HeadersLike, item: string): string | null => { + return typeof headers.get === "function" + ? headers.get(item) + : (headers as Record)[item]; };