Typescript and Koa BaseContext Issue

问题描述 投票:0回答:1

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/**/*"]
}
node.js typescript koa
1个回答
0
投票

在这里快速查看实际类型:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/koa/index.d.ts

有点像这些属性在BaseContext上不存在。

我可能会弄错,但是我相信要使用的正确类型是Context,而不是BaseContext。至少对我来说一直如此。

© www.soinside.com 2019 - 2024. All rights reserved.