我有以下代码:
const getConfig: IGetConfigRequestHandler = async (req, res) => { ... };
type IGetConfigRequestHandler = express.CustomRequestHandler<{ }, {
code: string;
timeout: string;
screen_timeout: string;
} | string>;
import express from 'express';
import * as core from 'express-serve-static-core';
declare module 'express' {
type CustomRequestHandler<
ReqBody = any,
ResBody = any,
ReqQuery extends core.Query = core.Query,
> = express.RequestHandler<core.ParamsDictionary, Readonly<ResBody>, Readonly<ReqBody>, Readonly<ReqQuery>>;
}
如果我将鼠标悬停在 req
上,我看不到 any
类型而是
(parameter) req: Request<ParamsDictionary, string | Readonly<{
code: string;
timeout: string;
screen_timeout: string;
}>, Readonly<{}>, Readonly<QueryString.ParsedQs>, Record<...>>
但是当我编译我的代码时出现错误:
Parameter 'req' implicitly has an 'any' type.
在 implicitAny
中取消 tsconfig.json
对我来说不是可选的。