mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): mark useRequestHeaders
keys as optional (#20286)
This commit is contained in:
parent
ac2e466175
commit
8aa86559c8
@ -4,8 +4,8 @@ import { setResponseStatus as _setResponseStatus } from 'h3'
|
|||||||
import type { NuxtApp } from '../nuxt'
|
import type { NuxtApp } from '../nuxt'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
export function useRequestHeaders<K extends string = string> (include: K[]): Record<Lowercase<K>, string | undefined>
|
export function useRequestHeaders<K extends string = string> (include: K[]): { [key in Lowercase<K>]?: string }
|
||||||
export function useRequestHeaders (): Readonly<Record<string, string | undefined>>
|
export function useRequestHeaders (): Readonly<Record<string, string>>
|
||||||
export function useRequestHeaders (include?: any[]) {
|
export function useRequestHeaders (include?: any[]) {
|
||||||
if (process.client) { return {} }
|
if (process.client) { return {} }
|
||||||
const headers = useNuxtApp().ssrContext?.event.node.req.headers ?? {}
|
const headers = useNuxtApp().ssrContext?.event.node.req.headers ?? {}
|
||||||
|
11
test/fixtures/basic/types.ts
vendored
11
test/fixtures/basic/types.ts
vendored
@ -260,6 +260,17 @@ describe('composables', () => {
|
|||||||
expectTypeOf(useLazyFetch('/api/hey', { default: () => 'bar', transform: v => v.foo }).data).toEqualTypeOf<Ref<string | null>>()
|
expectTypeOf(useLazyFetch('/api/hey', { default: () => 'bar', transform: v => v.foo }).data).toEqualTypeOf<Ref<string | null>>()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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<string | undefined>()
|
||||||
|
})
|
||||||
|
|
||||||
it('correctly types returns with key signatures', () => {
|
it('correctly types returns with key signatures', () => {
|
||||||
interface TestType {
|
interface TestType {
|
||||||
id: string
|
id: string
|
||||||
|
Loading…
Reference in New Issue
Block a user