types: Single key result with __typename still counts as single key (#1163)

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.
This commit is contained in:
Caleb Cox
2021-07-04 16:42:21 -05:00
committed by GitHub
parent c877bb89c6
commit 619b0d1e62
2 changed files with 3 additions and 1 deletions
@@ -6,4 +6,4 @@ export type IsUnion<T, U = T> = U extends any ? ([T] extends [U] ? false : true)
/**
* 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> = IsUnion<K> extends true ? T : T[K]
export type ExtractSingleKey<T, K extends keyof T = keyof T, KWithoutTypename extends K = Exclude<K, '__typename'>> = IsUnion<KWithoutTypename> extends true ? T : T[KWithoutTypename]
@@ -71,12 +71,14 @@ export interface ExampleUpdatedSubscriptionVariables {
}
export interface SingleKeyExampleQuery {
__typename?: 'Root'
example?: {
__typename?: 'Example'
}
}
export interface MultiKeyExampleQuery {
__typename?: 'Root'
example?: {
__typename?: 'Example'
}