diff --git a/src/api.ts b/src/api.ts index 9003a3edf..12f5a0b21 100644 --- a/src/api.ts +++ b/src/api.ts @@ -28,6 +28,12 @@ type IsNeverType = [T] extends [never] ? true : false; type StrictExtract = Cond extends Union ? Union : never; +type IsCaseMatched = + IsNeverType> extends false ? true : false; + +type GetCaseResult = + StrictExtract[1]; + export class APIClient { public origin: string; public credential: string | null | undefined; @@ -46,17 +52,18 @@ export class APIClient { public request( endpoint: E, params: P = {} as P, credential?: string | null | undefined, ): Promise> extends false - ? StrictExtract[1] - : IsNeverType> extends false - ? StrictExtract[1] - : IsNeverType> extends false - ? StrictExtract[1] - : IsNeverType> extends false - ? StrictExtract[1] - : IsNeverType> extends false - ? StrictExtract[1] - : Endpoints[E]['res']['$switch']['$default'] + ? + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + IsCaseMatched extends true ? GetCaseResult : + Endpoints[E]['res']['$switch']['$default'] : Endpoints[E]['res']> { const promise = new Promise((resolve, reject) => {