diff options
| author | zyoshoka <107108195+zyoshoka@users.noreply.github.com> | 2024-08-30 15:53:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-30 15:53:04 +0900 |
| commit | 8be624aa4441dbbc3f911453d22b70dee8a685b5 (patch) | |
| tree | e462548621295abd588559d01ddf434e45c2c191 /packages/sw/src/scripts/operations.ts | |
| parent | fix(frontend): server metrics look strange after reload (#14467) (diff) | |
| download | sharkey-8be624aa4441dbbc3f911453d22b70dee8a685b5.tar.gz sharkey-8be624aa4441dbbc3f911453d22b70dee8a685b5.tar.bz2 sharkey-8be624aa4441dbbc3f911453d22b70dee8a685b5.zip | |
refactor(sw): fix type errors (#14478)
* style(sw): lint fixes
* refactor(sw): fix type errors
* chore(sw): disable `noImplicitAny`
* ci(sw): enable typecheck ci
* ci(sw): build `misskey-js` before typecheck
Diffstat (limited to 'packages/sw/src/scripts/operations.ts')
| -rw-r--r-- | packages/sw/src/scripts/operations.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/packages/sw/src/scripts/operations.ts b/packages/sw/src/scripts/operations.ts index 24eea06231..8862c6faa5 100644 --- a/packages/sw/src/scripts/operations.ts +++ b/packages/sw/src/scripts/operations.ts @@ -14,15 +14,22 @@ import { getUrlWithLoginId } from '@/scripts/login-id.js'; export const cli = new Misskey.api.APIClient({ origin, fetch: (...args): Promise<Response> => fetch(...args) }); -export async function api<E extends keyof Misskey.Endpoints, O extends Misskey.Endpoints[E]['req']>(endpoint: E, userId?: string, options?: O): Promise<void | ReturnType<typeof cli.request<E, O>>> { - let account: { token: string; id: string } | void = undefined; +export async function api< + E extends keyof Misskey.Endpoints, + P extends Misskey.Endpoints[E]['req'] +>(endpoint: E, userId?: string, params?: P): Promise<Misskey.api.SwitchCaseResponseType<E, P> | undefined> { + let account: Pick<Misskey.entities.SignupResponse, 'id' | 'token'> | undefined; if (userId) { account = await getAccountFromId(userId); if (!account) return; } - return cli.request(endpoint, options, account?.token); + return (cli.request as <E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>( + endpoint: E, + params: P, + credential?: string | null, + ) => Promise<Misskey.api.SwitchCaseResponseType<E, P>>)(endpoint, params, account?.token); } // mark-all-as-read送出を1秒間隔に制限する @@ -33,7 +40,7 @@ export function sendMarkAllAsRead(userId: string): Promise<null | undefined | vo return new Promise(resolve => { setTimeout(() => { readBlockingStatus.set(userId, false); - api('notifications/mark-all-as-read', userId).then(resolve, resolve); + (api('notifications/mark-all-as-read', userId) as Promise<void>).then(resolve, resolve); }, 1000); }); } |