fix(nuxt): resolve type error in options of `useFetch` (#23693)

This commit is contained in:
Alex Liu 2023-10-16 19:56:37 +08:00 committed by GitHub
parent 1487c5631a
commit 732507b41f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -13,7 +13,7 @@ type AvailableRouterMethod<R extends NitroFetchRequest> = _AvailableRouterMethod
export type FetchResult<ReqT extends NitroFetchRequest, M extends AvailableRouterMethod<ReqT>> = TypedInternalResponse<ReqT, unknown, Lowercase<M>>
type ComputedOptions<T extends Record<string, any>> = {
[K in keyof T]: T[K] extends Function ? T[K] : T[K] extends Record<string, any> ? ComputedOptions<T[K]> | Ref<T[K]> | T[K] : Ref<T[K]> | T[K]
[K in keyof T]: T[K] extends Function ? T[K] : ComputedOptions<T[K]> | Ref<T[K]> | T[K]
}
interface NitroFetchOptions<R extends NitroFetchRequest, M extends AvailableRouterMethod<R> = AvailableRouterMethod<R>> extends FetchOptions {

View File

@ -406,6 +406,17 @@ describe('composables', () => {
expectTypeOf(test).toEqualTypeOf<string | undefined>()
})
it('allows passing reactive values in useFetch', () => {
useFetch('/api/hey', {
headers: {
key: ref('test')
},
query: {
param: computed(() => 'thing')
}
})
})
it('correctly types returns with key signatures', () => {
interface TestType {
id: string