现在我在自定义的.d.ts文件中有这个:
.replaceAll("[\\([0-9]\\%)]","");
我像这样引用该文件:
import { Request, Response, NextFunction } from 'express';
export type MiddleWareFn = (req: Request, res: Response, next: NextFunction) => void;
但是我想知道Express是否已经为中间件功能打字?
答案 0 :(得分:4)
是。您还需要导入RequestHandler
。检查定义here
import { RequestHandler } from 'express';
答案 1 :(得分:2)
这是我的处理方式:
import type { RequestHandler } from "express";
export const myMiddleware: RequestHandler = (req, res, next) => {
// HANDLE REQUEST
// RESPOND OR CALL NEXT()
};