Open wuxu1230 opened 9 months ago
为何只有 body 不能设置类型,难道只能使用 request.body as {...} 方式吗,希望解决下面的使用出现的类型丢失问题
request.body as {...}
源代码如下("@types/koa": "2.13.10", "@types/koa__router": "12.0.3")
import Router from "@koa/router" const router = new Router() interface KoaState { a: string } interface Context { request: { params: { id: string } body: { c: string } body2: { d: string } } } interface ResponseBody { b: string } router.post<KoaState, Context, ResponseBody>("/:id", async (ctx) => { const {state, request, response} = ctx const a = state.a const id = request.params.id const c = request.body.c const d = request.body2.d const b = response.body.b })
为何只有 body 不能设置类型,难道只能使用![image](https://github.com/koajs/router/assets/46241389/9b4e6527-16ba-42a6-a733-953a6fee01b7)
request.body as {...}
方式吗,希望解决下面的使用出现的类型丢失问题源代码如下("@types/koa": "2.13.10", "@types/koa__router": "12.0.3")