fix(nuxt): return type directly if not picking asyncData (#20288)

This commit is contained in:
Daniel Roe 2023-04-15 11:03:09 +01:00 committed by GitHub
parent d0c8e7fb4a
commit 3754591257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -11,14 +11,16 @@ 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
: Pick<T, K[number]>
: K[number] extends never
? T
: Pick<T, K[number]>
: T
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
>

View File

@ -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', () => {