Skip to content

Commit

Permalink
fix(headers): types
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Jul 1, 2024
1 parent c808573 commit c3c9bb6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/utils/headers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import cookieParser from "set-cookie-parser";

export const retrieveResponseCookies = (headers: Record<string, string> | Headers): string[] => {
interface HeadersLike {
get (key: string): string | null
};

export const retrieveResponseCookies = (headers: Record<string, string> | Headers | HeadersLike): string[] => {
const setCookieHeader = getHeaderFromFetcherResponse(headers, "set-cookie");
if (setCookieHeader === null) return [];

Expand All @@ -10,6 +14,8 @@ export const retrieveResponseCookies = (headers: Record<string, string> | Header
return cookies;
};

export const getHeaderFromFetcherResponse = (headers: Record<string, string> | Headers, item: string): string | null => {
return (typeof headers.get === "function") ? headers.get(item) : headers[item];
export const getHeaderFromFetcherResponse = (headers: Record<string, string> | Headers | HeadersLike, item: string): string | null => {
return typeof headers.get === "function"
? headers.get(item)
: (headers as Record<string, string>)[item];
};

0 comments on commit c3c9bb6

Please sign in to comment.