From 46900728d3bcdbd9041f99615086f901502a819f Mon Sep 17 00:00:00 2001 From: Saravana Achu Mac Date: Mon, 4 May 2026 15:17:33 -0700 Subject: [PATCH] chore(api-client): type header merging Replace the Headers branch's any cast with a typed copy into a Record so the shared API client keeps the same header merge behavior without a no-explicit-any warning. Verification: pnpm --filter @bytelyst/api-client build; pnpm --filter @bytelyst/api-client test; pnpm --filter @bytelyst/api-client exec eslint . --ext .ts,.tsx; pnpm lint. --- packages/api-client/src/client.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/api-client/src/client.ts b/packages/api-client/src/client.ts index d55141e5..82309665 100644 --- a/packages/api-client/src/client.ts +++ b/packages/api-client/src/client.ts @@ -42,9 +42,10 @@ export function createApiClient(config: ApiClientConfig): ApiClient { function buildHeaders(options?: RequestInit): HeadersInit { const headers: Record = { 'Content-Type': 'application/json', - 'x-request-id': typeof globalThis.crypto?.randomUUID === 'function' - ? globalThis.crypto.randomUUID() - : `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`, + 'x-request-id': + typeof globalThis.crypto?.randomUUID === 'function' + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`, ...defaultHeaders, }; @@ -56,12 +57,16 @@ export function createApiClient(config: ApiClientConfig): ApiClient { } if (options?.headers) { - const extra = - options.headers instanceof Headers - ? Object.fromEntries(options.headers as any) - : Array.isArray(options.headers) - ? Object.fromEntries(options.headers) - : (options.headers as Record); + const extra: Record = {}; + if (options.headers instanceof Headers) { + options.headers.forEach((value, key) => { + extra[key] = value; + }); + } else if (Array.isArray(options.headers)) { + Object.assign(extra, Object.fromEntries(options.headers)); + } else { + Object.assign(extra, options.headers); + } Object.assign(headers, extra); }