diff --git a/packages/frontend/src/scripts/api.ts b/packages/frontend/src/scripts/api.ts index ab8d70e4b..e3f30a908 100644 --- a/packages/frontend/src/scripts/api.ts +++ b/packages/frontend/src/scripts/api.ts @@ -5,9 +5,9 @@ import { $i } from '@/account'; export const pendingApiRequestsCount = ref(0); // Implements Misskey.api.ApiClient.request -export function api, D extends IEndpointMeta = Endpoints[E]>( +export function api, M extends IEndpointMeta = Endpoints[E]>( endpoint: E, params?: P, token?: string | null | undefined, signal?: AbortSignal -): Promise> { +): Promise> { const data: (P | Record) & { i?: string | null } = params ?? {}; pendingApiRequestsCount.value++; @@ -16,7 +16,7 @@ export function api | void>((resolve, reject) => { + const promise = new Promise | void>((resolve, reject) => { // Append a credential if ($i) data.i = $i.token; if (token !== undefined) data.i = token; @@ -46,13 +46,13 @@ export function api>; + return promise as Promise>; } // Implements Misskey.api.ApiClient.request -export function apiGet, D extends IEndpointMeta = Endpoints[E]>( +export function apiGet, M extends IEndpointMeta = Endpoints[E]>( endpoint: E, params?: P, token?: string | null | undefined, signal?: AbortSignal -): Promise> { +): Promise> { pendingApiRequestsCount.value++; const onFinally = () => { @@ -61,7 +61,7 @@ export function apiGet); - const promise = new Promise | void>((resolve, reject) => { + const promise = new Promise | void>((resolve, reject) => { // Send request window.fetch(`${apiUrl}/${endpoint}?${query}`, { method: 'GET', @@ -82,5 +82,5 @@ export function apiGet>; + return promise as Promise>; } diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index ebade1693..ebb2a263b 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -42,9 +42,9 @@ export class APIClient { this.fetch = opts.fetch ?? ((...args) => fetch(...args)); } - public request, D extends IEndpointMeta = Endpoints[E], R = ResponseOf>( + public request, M extends IEndpointMeta = Endpoints[E]>( endpoint: E, params: P, credential?: string | null | undefined, - ): Promise + ): Promise> { const promise = new Promise((resolve, reject) => { this.fetch(`${this.origin}/api/${endpoint}`, { @@ -74,6 +74,6 @@ export class APIClient { }).catch(reject); }); - return promise as any; + return promise as Promise>; } } diff --git a/packages/misskey-js/src/index.ts b/packages/misskey-js/src/index.ts index 797f10a4e..457a2742f 100644 --- a/packages/misskey-js/src/index.ts +++ b/packages/misskey-js/src/index.ts @@ -1,4 +1,4 @@ -import { Endpoints } from './api.types.js'; +import { Endpoints } from './endpoints.types.js'; import Stream, { Connection } from './streaming.js'; import { Channels } from './streaming.types.js'; import { Acct } from './acct.js';