Skip to content

Commit 4f3ee6e

Browse files
authored
Merge pull request #111 from maxmellen/strict-ts
Improve Type Declarations
2 parents 8566ca5 + 5cbd48f commit 4f3ee6e

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

index.d.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export declare interface FileOptions {
2727
maxAge?: number;
2828
root?: string;
2929
lastModified?: boolean | string;
30-
headers?: {};
30+
headers?: { [key: string]: string };
3131
cacheControl?: boolean | string;
3232
private?: boolean;
3333
}
@@ -36,10 +36,10 @@ export declare interface App {
3636
[namespace: string]: HandlerFunction;
3737
}
3838

39-
export declare type Middleware = (req: Request, res: Response, next: Middleware) => void;
39+
export declare type Middleware = (req: Request, res: Response, next: () => void) => void;
4040
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void;
4141
export declare type ErrorCallback = (error?: Error) => void;
42-
export declare type HandlerFunction = (req?: Request, res?: Response, next?: NextFunction) => void | {} | Promise<{}>;
42+
export declare type HandlerFunction = (req: Request, res: Response, next?: NextFunction) => void | any | Promise<any>;
4343
export declare type LoggerFunction = (message: string) => void;
4444
export declare type NextFunction = () => void;
4545
export declare type TimestampFunction = () => string;
@@ -80,7 +80,7 @@ export declare interface LoggerOptions {
8080
rules?: SamplingOptions[];
8181
};
8282
serializers?: {
83-
[name: string]: (req: Request) => {};
83+
[name: string]: (prop: any) => any;
8484
};
8585
stack?: boolean;
8686
}
@@ -100,17 +100,21 @@ export declare class Request {
100100
app: API;
101101
version: string;
102102
id: string;
103-
params: {};
103+
params: {
104+
[key: string]: string | undefined;
105+
};
104106
method: string;
105107
path: string;
106108
query: {
107-
[key: string]: string;
109+
[key: string]: string | undefined;
108110
};
109111
headers: {
110-
[key: string]: string;
112+
[key: string]: string | undefined;
111113
};
112-
rawHeaders?: {};
113-
body: {} | string;
114+
rawHeaders?: {
115+
[key: string]: string | undefined;
116+
};
117+
body: any;
114118
rawBody: string;
115119
route: '';
116120
requestContext: APIGatewayEventRequestContext;
@@ -119,8 +123,8 @@ export declare class Request {
119123
stageVariables: { [name: string]: string } | null;
120124
auth: {
121125
[key: string]: any;
122-
type: 'Bearer' | 'Basic' | 'OAuth' | 'Digest';
123-
value: string;
126+
type: 'Bearer' | 'Basic' | 'OAuth' | 'Digest' | 'none';
127+
value: string | null;
124128
};
125129
cookies: {
126130
[key: string]: CookieOptions;
@@ -141,15 +145,18 @@ export declare class Request {
141145
error: LoggerFunction;
142146
fatal: LoggerFunction;
143147
};
148+
149+
[key: string]: any;
144150
}
145151

146152
export declare class Response {
147153
status(code: number): this;
154+
sendStatus(code: number): void;
148155
header(key: string, value: string): this;
149156
getHeader(key: string): string;
150157
hasHeader(key: string): boolean;
151158
removeHeader(key: string): this;
152-
getLink(s3Path: string, expires?: number, callback?: (err, data) => void);
159+
getLink(s3Path: string, expires?: number, callback?: ErrorCallback): Promise<string>;
153160
send(body: any): void;
154161
json(body: any): void;
155162
jsonp(body: any): void;
@@ -159,16 +166,16 @@ export declare class Response {
159166
redirect(status: number, path: string): void;
160167
redirect(path: string): void;
161168
cors(options: CorsOptions): this;
162-
error(message: string, detail?: any);
163-
error(code: number, message: string, detail?: any);
169+
error(message: string, detail?: any): void;
170+
error(code: number, message: string, detail?: any): void;
164171
cookie(name: string, value: string, options?: CookieOptions): this;
165172
clearCookie(name: string, options?: CookieOptions): this;
166173
etag(enable?: boolean): this;
167174
cache(age?: boolean | number | string, private?: boolean): this;
168175
modified(date: boolean | string | Date): this;
169176
attachment(fileName?: string): this;
170-
download(file: string | Buffer, fileName?: string, options?: FileOptions, callback?: ErrorCallback);
171-
sendFile(file: string | Buffer, options?: FileOptions, callback?: ErrorCallback);
177+
download(file: string | Buffer, fileName?: string, options?: FileOptions, callback?: ErrorCallback): void;
178+
sendFile(file: string | Buffer, options?: FileOptions, callback?: ErrorCallback): Promise<void>;
172179
}
173180

174181
export declare class API {
@@ -197,10 +204,10 @@ export declare class API {
197204

198205

199206

200-
use(path: string, ...middleware: Middleware[]);
201-
use(paths: string[], ...middleware: Middleware[]);
202-
use (...middleware: Middleware[]);
203-
use (...errorHandlingMiddleware: ErrorHandlingMiddleware[]);
207+
use(path: string, ...middleware: Middleware[]): void;
208+
use(paths: string[], ...middleware: Middleware[]): void;
209+
use(...middleware: Middleware[]): void;
210+
use(...errorHandlingMiddleware: ErrorHandlingMiddleware[]): void;
204211

205212
finally(callback: FinallyFunction): void;
206213

package-lock.json

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)