打字稿抱怨输入任何参数,尽管它不是任何类型

时间:2021-03-30 08:44:00

标签: node.js typescript express

我有以下代码:

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 对我来说不是可选的。

0 个答案:

没有答案