UNPKG

2.43 kBTypeScriptView Raw
1// copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/superagent/superagent.d.ts
2// I don't like the dependency on node definitions, so I removed them
3declare module "superagent" {
4 type CallbackHandler = (err: any, res: request.Response) => void;
5
6 var request: request.SuperAgentStatic;
7
8 namespace request {
9 interface SuperAgentStatic extends SuperAgent<SuperAgentRequest> {
10 (url: string): SuperAgentRequest;
11 (method: string, url: string): SuperAgentRequest;
12
13 agent(): SuperAgent<SuperAgentRequest>;
14 }
15
16 interface SuperAgent<Req extends Request<any>> {
17 get(url: string): Req;
18 post(url: string): Req;
19 put(url: string): Req;
20 patch(url: string): Req;
21 delete(url: string): Req;
22 head(url: string): Req;
23 options(url: string): Req;
24 }
25
26 interface Response {
27 text: string;
28 body: any;
29 files: any;
30 header: any;
31 type: string;
32 charset: string;
33 status: number;
34 statusType: number;
35 info: boolean;
36 ok: boolean;
37 redirect: boolean;
38 clientError: boolean;
39 serverError: boolean;
40 error: Error;
41 accepted: boolean;
42 noContent: boolean;
43 badRequest: boolean;
44 unauthorized: boolean;
45 notAcceptable: boolean;
46 notFound: boolean;
47 forbidden: boolean;
48 get(header: string): string;
49 }
50
51 interface Request<Req extends Request<any>> {
52 abort(): void;
53 accept(type: string): Req;
54 attach(field: string, file: string, filename?: string): Req;
55 auth(user: string, name: string): Req;
56 buffer(val: boolean): Req;
57 clearTimeout(): Req;
58 end(callback?: CallbackHandler): Req;
59 field(name: string, val: string): Req;
60 get(field: string): string;
61 on(name: string, handler: Function): Req;
62 on(name: 'error', handler: (err: any) => void): Req;
63 part(): Req;
64 query(val: Object): Req;
65 redirects(n: number): Req;
66 send(data: string): Req;
67 send(data: Object): Req;
68 send(): Req;
69 set(field: string, val: string): Req;
70 set(field: Object): Req;
71 timeout(ms: number): Req;
72 type(val: string): Req;
73 use(fn: Function): Req;
74 withCredentials(): Req;
75 write(data: string, encoding?: string): Req;
76 }
77 interface SuperAgentRequest extends Request<Request<Request<Request<any>>>> {}
78
79 }
80
81 export = request;
82}