mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): return type directly if not picking asyncData (#20288)
This commit is contained in:
parent
d0c8e7fb4a
commit
3754591257
@ -11,6 +11,8 @@ export type PickFrom<T, K extends Array<string>> = T extends Array<any>
|
||||
: T extends Record<string, any>
|
||||
? keyof T extends K[number]
|
||||
? T // Exact same keys as the target, skip Pick
|
||||
: K[number] extends never
|
||||
? T
|
||||
: Pick<T, K[number]>
|
||||
: T
|
||||
|
||||
@ -18,7 +20,7 @@ export type KeysOf<T> = Array<
|
||||
T extends T // Include all keys of union types, not just common keys
|
||||
? keyof T extends string
|
||||
? keyof T
|
||||
: string
|
||||
: never
|
||||
: never
|
||||
>
|
||||
|
||||
|
15
test/fixtures/basic/types.ts
vendored
15
test/fixtures/basic/types.ts
vendored
@ -259,6 +259,21 @@ describe('composables', () => {
|
||||
expectTypeOf(useFetch('/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('correctly types returns with key signatures', () => {
|
||||
interface TestType {
|
||||
id: string
|
||||
content: string[]
|
||||
[x: string]: any
|
||||
}
|
||||
|
||||
const testFetch = () => Promise.resolve({}) as Promise<TestType>
|
||||
|
||||
const { data: notTypedData } = useAsyncData('test', testFetch)
|
||||
expectTypeOf(notTypedData.value!.id).toEqualTypeOf<string>()
|
||||
expectTypeOf(notTypedData.value!.content).toEqualTypeOf<string[]>()
|
||||
expectTypeOf(notTypedData.value!.untypedKey).toEqualTypeOf<any>()
|
||||
})
|
||||
})
|
||||
|
||||
describe('app config', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user