Typescript抛出错误消息,请求在BaseContext类型中不存在。那不可能是因为我以前使用过代码并且可以正常工作。
类型'BaseContext'上不存在属性'request'。
import { BaseContext } from 'koa'
export function handle(ctx: BaseContext) {
ctx.body = ctx.request.body
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": "."
},
"include": ["src/**/*", "env/**/*"]
}
在这里快速查看实际类型:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/koa/index.d.ts
有点像这些属性在BaseContext
上不存在。
我可能会弄错,但是我相信要使用的正确类型是Context
,而不是BaseContext
。至少对我来说一直如此。