From a7476affe6a73b3bfc1ce944438681275d7915fa Mon Sep 17 00:00:00 2001 From: dojyorin Date: Wed, 22 Nov 2023 18:50:51 +0900 Subject: [PATCH] improve type select. --- src/fetch.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index ec2af80..3c5d7a9 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -10,7 +10,10 @@ export interface FetchInit extends Omit{ query?: URLSearchParams; secret?: { key: string; + id?: undefined; + pw?: undefined; } | { + key?: undefined; id: string; pw: string; }; @@ -50,14 +53,12 @@ export async function fetchExtend(path:string, typ u.searchParams.set(k, v); } - if(option?.secret){ - if("key" in option.secret){ - h.set("Authorization", `Bearer ${option.secret.key}`); - } - else{ - u.username = option.secret.id; - u.password = option.secret.pw; - } + if(option?.secret?.key){ + h.set("Authorization", `Bearer ${option.secret.key}`); + } + else if(option?.secret?.id){ + u.username = option.secret.id; + u.password = option.secret.pw; } const response = await fetch(u.href, {