打字稿和Koa BaseContext问题

Typescript抛出错误消息,请求不存在BaseContext类型。那不可能是因为我以前使用过代码并且可以正常工作。

  

类型“ BaseContext”上不存在属性“请求”。

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/**/*"]
}
tttaaannnzzzhhhiii 回答:打字稿和Koa BaseContext问题

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

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

似乎这些属性在WRONG_MESSAGE上不存在。最近似乎对此也做了一些更改。

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

本文链接:https://www.f2er.com/3169541.html

大家都在问