619b0d1e62
Previously, a response with a single key and a __typename field would not be considered as having a single key and could not be automatically extracted by useQuery.
10 lines
435 B
TypeScript
10 lines
435 B
TypeScript
/**
|
|
* Check if a type is a union, and return true if so, otherwise false.
|
|
*/
|
|
export type IsUnion<T, U = T> = U extends any ? ([T] extends [U] ? false : true) : never
|
|
|
|
/**
|
|
* Extracts an inner type if T has a single key K, otherwise it returns T.
|
|
*/
|
|
export type ExtractSingleKey<T, K extends keyof T = keyof T, KWithoutTypename extends K = Exclude<K, '__typename'>> = IsUnion<KWithoutTypename> extends true ? T : T[KWithoutTypename]
|