使用全局注册中间件类型错误 #4581
TsMask
started this conversation in
General / 闲聊
使用全局注册中间件类型错误
#4581
Replies: 3 comments
|
临时解决加any就行 |
0 replies
|
+1 |
0 replies
|
这个看起来是 ctx 类型推导被收窄了,不是运行时注册方式的问题。
建议中间件这样写,ctx 用 Midway Koa 的上下文类型,不要直接用带组件增强字段的 import { IMidwayKoaContext, NextFunction } from @midwayjs/koa;
import { Middleware } from @midwayjs/core;
@Middleware()
export class ReportMiddleware {
resolve() {
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
// 如果启用了 security 组件,这里可以按需访问 ctx.security
await next();
};
}
}如果业务里一定要强类型访问 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
使用全局注册中间件类型错误,无法启动
this.app.useMiddleware([ReportMiddleware]);All reactions