Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 拓展ts类型提示 #283

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions index.d.ts
Expand Up @@ -23,6 +23,8 @@ export interface FlyResponse<T = any> {
request: FlyRequestConfig;
engine: XMLHttpRequest;
headers: Object;
status:number;
statusText:string
}

export interface FlyErrResponse {
Expand All @@ -35,14 +37,16 @@ export interface FlyErrResponse {
export interface FlyPromise<T = any> extends Promise<FlyResponse<T>> {
}

export type UntieResponse<T = any, O = any> = O extends keyof FlyResponse ? Promise<FlyResponse<T>[O]> : Promise<FlyResponse<T>>

export interface FlyRequestInterceptor<V> {
use(onSend?: (request: V) => any): void;
lock(): void;
unlock(): void;

clear(): void;
}
export interface FlyResponseInterceptor<V> {
export interface FlyResponseInterceptor<V = FlyResponse> {
use(onSucceed?: (response: V) => any, onError?: (err: Error) => any): void;
lock(): void;
unlock(): void;
Expand All @@ -57,11 +61,11 @@ export interface Fly {
response:FlyResponseInterceptor<FlyResponse>;
};
engine:any;
request<T = any>(url: string, data?: any, config?: FlyRequestConfig): FlyPromise<T>;
get<T = any>(url: string, data?:any, config?: FlyRequestConfig): FlyPromise<T>;
request<D = any, T = any,O extends string = ''>(url: string, data?: D, config?: FlyRequestConfig): UntieResponse<T,O>;
get<D = any,T = any, O extends string = ''>(url: string, data?:D, config?: FlyRequestConfig): UntieResponse<T,O>;
delete(url: string, data?:any, config?: FlyRequestConfig): FlyPromise;
head(url: string,data?:any, config?: FlyRequestConfig): FlyPromise;
post<T = any>(url: string, data?: any, config?: FlyRequestConfig): FlyPromise<T>;
post<D = any,T = any, O extends string = ''>(url: string, data?: D, config?: FlyRequestConfig): UntieResponse<T,O>;
put<T = any>(url: string, data?: any, config?: FlyRequestConfig): FlyPromise<T>;
patch<T = any>(url: string, data?: any, config?: FlyRequestConfig): FlyPromise<T>;
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
Expand Down