bodyparser
bodyparser copied to clipboard
Why is body typed as string? gives tsc compilation errors
Why is this library not self typed. Now the type definition somewhere else is like:
declare module 'koa' {
interface Request {
body: string | Record<string, unknown>;
rawBody: string;
}
}
It seems i have to drop it at https://www.npmjs.com/package/@types/koa-bodyparser
Hello there, can you share how did you manage to resolve this issue?
Hi, i pinned it to version 4.3.0
untill its fixed correctly :)
Having the same issue... pinning @types/koa-bodyparser at 4.3.0
resolves it for now - but I'd like to see this fixed!
For now I use only application/json bodies so I did that:
const myInternalVar:MyInternalType = JSON.parse(ctx.request.rawBody);
It's ugly but it works.
Hey guys, I would mention that I have re-created the module with TS so no need to
@types/koa-bodyparser
in the future (once the PR merged).For a quick solution about the typing behave, you can override the request signature like this
declare module "koa" { interface Request { body?: Record<string, unknown>; // BTW, you can override it to any type you want ... rawBody: string; } }