diff --git a/packages/nuxt/src/app/composables/ssr.ts b/packages/nuxt/src/app/composables/ssr.ts index f4c30eca8c..9b2e883af4 100644 --- a/packages/nuxt/src/app/composables/ssr.ts +++ b/packages/nuxt/src/app/composables/ssr.ts @@ -4,8 +4,8 @@ import { setResponseStatus as _setResponseStatus } from 'h3' import type { NuxtApp } from '../nuxt' import { useNuxtApp } from '../nuxt' -export function useRequestHeaders (include: K[]): Record, string | undefined> -export function useRequestHeaders (): Readonly> +export function useRequestHeaders (include: K[]): { [key in Lowercase]?: string } +export function useRequestHeaders (): Readonly> export function useRequestHeaders (include?: any[]) { if (process.client) { return {} } const headers = useNuxtApp().ssrContext?.event.node.req.headers ?? {} diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts index 61eb67d5b4..b76f065b0d 100644 --- a/test/fixtures/basic/types.ts +++ b/test/fixtures/basic/types.ts @@ -260,6 +260,17 @@ describe('composables', () => { expectTypeOf(useLazyFetch('/api/hey', { default: () => 'bar', transform: v => v.foo }).data).toEqualTypeOf>() }) + it('uses types compatible between useRequestHeaders and useFetch', () => { + useFetch('/api/hey', { + headers: useRequestHeaders() + }) + useFetch('/api/hey', { + headers: useRequestHeaders(['test']) + }) + const { test } = useRequestHeaders(['test']) + expectTypeOf(test).toEqualTypeOf() + }) + it('correctly types returns with key signatures', () => { interface TestType { id: string