Archived
1
0
Fork 0
This repository has been archived on 2024-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
api-ts-gen/dist/utils/APIPromise.d.ts

30 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-06-13 21:06:21 +09:00
import { AxiosPromise, AxiosResponse } from 'axios';
declare type ValueOf<T> = T[keyof T];
declare type RHandler<T> = ValueOf<{
[K in keyof T]: T[K] extends (data: any) => infer U ? U : never;
}>;
export declare class BadResponseError extends Error {
2022-06-13 21:06:21 +09:00
res: AxiosResponse;
constructor(res: AxiosResponse, label: string);
}
export declare class APIPromise<TRes, KRsv extends keyof TRes, THdl extends {
[K in KRsv]: (data: TRes[K]) => any;
}, KOn extends keyof TRes = keyof TRes> implements PromiseLike<RHandler<THdl>> {
private handlers;
private promise;
2022-06-13 21:06:21 +09:00
constructor(resPromise: AxiosPromise, stps: {
[K in keyof TRes]: (data: any) => TRes[K];
}, handlers: THdl);
2022-06-13 21:06:21 +09:00
static init<TRes, KRsv extends keyof TRes>(res: AxiosPromise, stps: {
[K in keyof TRes]: (data: any) => TRes[K];
}, kRsvs: KRsv[]): APIPromise<TRes, KRsv, {
[K in KRsv]: (data: TRes[K]) => TRes[K];
}>;
on<KK extends KOn, URst>(status: KK, handler: (data: TRes[KK]) => URst): APIPromise<TRes, KRsv | KK, {
[K in (KRsv | KK)]: (data: TRes[K]) => K extends KK ? URst : K extends keyof THdl ? ReturnType<THdl[K]> : never;
}, Exclude<KOn, KK>>;
then<RRsv = never, RRjt = never>(onRsv?: (value: RHandler<THdl>) => RRsv | PromiseLike<RRsv>, onRjt?: (reason: any) => RRjt | PromiseLike<RRjt>): Promise<RRsv | RRjt>;
catch<RRjt>(onRjt: (reason: any) => RRjt | PromiseLike<RRjt>): Promise<RRjt>;
}
export {};