koa-body icon indicating copy to clipboard operation
koa-body copied to clipboard

Property 'files' or 'body' does not exist on type 'Request'

Open richerfu opened this issue 5 years ago • 5 comments

Problem/Feature Request Summary

when my context is custom and use koa-body in typesciprt, Property 'files' does not exist on type 'Request' or Property 'body' does not exist on type 'Request'

Environment Information

  • koa-body:^4.1.1
  • Koa: ^2.11.0
  • Node.js:10.13.0

Current Behavior

image image

Steps to Reproduce

Expected Behavior

Possible Solution

Context (Environment)

richerfu avatar Dec 16 '19 05:12 richerfu

Same issue here. @southorange1228, are you by any chance using pnpm too?

Aankhen avatar Jan 12 '20 20:01 Aankhen

i just custom interface in order to solve this problem.

export interface SoRequest extends Request {
  body?: any;
  files?: Files;
}

export interface SoContext extends Koa.Context {
  request: SoRequest;
}

and i never use pnpm

richerfu avatar Jan 13 '20 05:01 richerfu

version:5.0.0 pnpm also bugs,please fix

xygengcn avatar Aug 28 '22 14:08 xygengcn

maybe you should define the middleware Type import { MiddleWare } from '@koa/router' type Middleware from @koa/router or koa

// xxx.ts

interface BodyType {
  // whatever
}

const controller: Middleware = async (ctx) => {
  const body = ctx.request.body as BodyType
  // something
}
app.use(controller)

1eejay avatar Oct 12 '22 03:10 1eejay

Problem still exists Version: 6.0.1

idkwimd avatar Jul 08 '24 14:07 idkwimd