我用的是特快专递打字本。我想扩展我的快速请求接口,因为我所做的事情如下:-
Middleware.ts
import { NextFunction, Request, Response } from 'express';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configureI18n = require('../helpers/i18n');
const [_, i18nObj] = configureI18n(false);
export interface CRequest extends Request {
i18nObj: any;
}
const langHeadersMiddleware = (
request: CRequest,
response: Response,
next: NextFunction
): void => {
try {
const language = request.headers['accept-language'];
i18nObj.setLocale(language ? language : 'en');
request.i18nObj = i18nObj;
next();
} catch (error) {
i18nObj.setLocale('en');
}
};
export default langHeadersMiddleware;route.ts
getUserProfile.get(
'/:id',
async (request: CRequest, response: express.Response) => {
try {
const id = request.params.id;
response.json({
err: 0,
message: request.i18nObj.__('MESSAGES.USER_FETCH'),
data
});
} catch (error: any) {
response.json({ err: 1, message: error.message, error });
}
}
);在这条路上,我遇到了一个错误:-
没有重载与此调用匹配。最后一次重载导致以下错误。类型的参数(请求: CRequest,响应: express.Response) =>允诺‘不能分配给'Application’的参数。类型‘(请求: CRequest,响应: Response>) =>允诺’在'Application‘:init,defaultConfiguration,engine,set等类型中缺少以下属性。
我看了那么多博客,文章,但每个人都在使用和我一样。
发布于 2022-08-18 08:53:02
您将不得不对整个快递包进行分叉和返工,这绝对不推荐:)
但你可以:
https://stackoverflow.com/questions/73399825
复制相似问题