Skip to content

Commit 5d4a014

Browse files
authored
Merge pull request #148 from stawecki/issue-137
TypeScript support for api.register/routes, req.namespace (issue #137)
2 parents 0f3af15 + 281b106 commit 5d4a014

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

index.d.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ export declare interface FileOptions {
3232
private?: boolean;
3333
}
3434

35+
export declare interface RegisterOptions {
36+
prefix?: string;
37+
}
38+
39+
export type Package = any;
40+
3541
export declare interface App {
36-
[namespace: string]: HandlerFunction;
42+
[namespace: string]: Package;
3743
}
3844

3945
export declare type Middleware = (req: Request, res: Response, next: () => void) => void;
40-
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void;
46+
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: () => void) => void;
4147
export declare type ErrorCallback = (error?: Error) => void;
4248
export declare type HandlerFunction = (req: Request, res: Response, next?: NextFunction) => void | any | Promise<any>;
4349
export declare type LoggerFunction = (message: string) => void;
@@ -138,6 +144,7 @@ export declare class Request {
138144
userAgent: string;
139145
clientType: 'desktop' | 'mobile' | 'tv' | 'tablet' | 'unknown';
140146
clientCountry: string;
147+
namespace: App;
141148

142149
log: {
143150
trace: LoggerFunction;
@@ -181,8 +188,8 @@ export declare class Response {
181188
}
182189

183190
export declare class API {
184-
app(namespace: string, handler: HandlerFunction): App;
185-
app(options: App): App;
191+
app(namespace: string, package: Package): App;
192+
app(packages: App): App;
186193

187194
get(path: string, ...handler: HandlerFunction[]): void;
188195
get(...handler: HandlerFunction[]): void;
@@ -202,7 +209,10 @@ export declare class API {
202209
any(...handler: HandlerFunction[]): void;
203210
METHOD(method: METHODS, path: string, ...handler: HandlerFunction[]): void;
204211
METHOD(method: METHODS, ...handler: HandlerFunction[]): void;
205-
212+
register(routes: (api: API, options?: RegisterOptions) => void, options?: RegisterOptions): void;
213+
routes(format: true): void;
214+
routes(format: false): string[][];
215+
routes(): string[][];
206216

207217

208218

0 commit comments

Comments
 (0)