为API抽象类添加注解和类型限定
This commit is contained in:
@@ -1,11 +1,22 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
import Logger from "../Logger";
|
import Logger from "../Logger";
|
||||||
|
|
||||||
|
interface MiddlewareFunction {
|
||||||
|
(req: Request, res: Response, next: NextFunction): void;
|
||||||
|
}
|
||||||
|
|
||||||
abstract class API {
|
abstract class API {
|
||||||
|
|
||||||
protected logger: Logger;
|
protected logger: Logger;
|
||||||
public middlewareFunc: Function[] = [];
|
public middlewareFunc: Function[] = [];
|
||||||
constructor(public method: string, public uri: string, ...func: any) {
|
|
||||||
this.logger = new Logger('API][' + method + '][' + uri);
|
/**
|
||||||
|
* @param method API方法
|
||||||
|
* @param path API路由Path
|
||||||
|
* @param func API中间件函数
|
||||||
|
*/
|
||||||
|
constructor(public method: string, public path: string, ...func: MiddlewareFunction[]) {
|
||||||
|
this.logger = new Logger('API][' + method + '][' + path);
|
||||||
this.middlewareFunc.push(...func);
|
this.middlewareFunc.push(...func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user