fix(types): tidy types for useAsyncData (#5340)

This commit is contained in:
Anthony Fu 2022-06-09 03:45:12 +08:00 committed by GitHub
parent 822928b07e
commit eafd92c457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,14 @@ import { NuxtApp, useNuxtApp } from '#app'
export type _Transform<Input = any, Output = any> = (input: Input) => Output
export type PickFrom<T, K extends Array<string>> = T extends Array<any> ? T : T extends Record<string, any> ? Pick<T, K[number]> : T
export type PickFrom<T, K extends Array<string>> = T extends Array<any>
? T
: T extends Record<string, any>
? keyof T extends K[number]
? T // Exact same keys as the target, skip Pick
: Pick<T, K[number]>
: T
export type KeysOf<T> = Array<keyof T extends string ? keyof T : string>
export type KeyOfRes<Transform extends _Transform> = KeysOf<ReturnType<Transform>>