From d0dc0f2bd1acefe529cb66e217d5bfd7bce2e2c4 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 3 Apr 2022 17:15:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20SammoAPICall=EC=97=90=EC=84=9C=20arg?= =?UTF-8?q?=EA=B0=80=20=EC=A7=80=EC=A0=95=EB=90=98=EC=96=B4=EB=8F=84=20und?= =?UTF-8?q?efined=EA=B0=80=20=EA=B0=80=EB=8A=A5=ED=95=9C=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/util/callSammoAPI.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/hwe/ts/util/callSammoAPI.ts b/hwe/ts/util/callSammoAPI.ts index 9e7b0788..451cd90a 100644 --- a/hwe/ts/util/callSammoAPI.ts +++ b/hwe/ts/util/callSammoAPI.ts @@ -13,12 +13,27 @@ export type InvalidResponse = { export type RawArgType = Record | Record[] | undefined; -export interface APICallT { - (args?: ArgType): Promise; - (args: ArgType | undefined, returnError: false): Promise; - (args: ArgType | undefined, returnError: true): Promise; +interface BasicAPICallT { + (args: ArgType): Promise; + (args: ArgType, returnError: false): Promise; + (args: ArgType, returnError: true): Promise; } +interface EmptyAPICallT { + (): Promise; + (args: undefined): Promise; + (args: undefined, returnError: false): Promise; + (args: undefined, returnError: true): Promise; +} + +export type APICallT< + ArgType extends RawArgType, + ResultType extends ValidResponse = ValidResponse, + ErrorType extends InvalidResponse = InvalidResponse + > = ArgType extends undefined + ? EmptyAPICallT + : BasicAPICallT; + type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete'; export type APITail = typeof GET | typeof POST | typeof PUT | typeof PATCH | typeof HEAD | typeof DELETE;