Closed jeengbe closed 5 months ago
@jeengbe Can you provide the version of 'koa' what you use plz.
Since that might cause by req
field is not found in KoaRequest.
Sorry, I forgot to add this code snippet; this is what tsoa generates:
const args: Record<string, TsoaRoute.ParameterSchema> = {
undefined: {"in":"request","required":true,"dataType":"object"},
};
I assume this is because the parameter has no name, instead, is deconstructed directly. This issue was introduced with tsoa 6.1 and works fine on 6.0.
@jeengbe I dig a little bit into the code.
This issue is not directly cause by recently update(^6.0.1), but discovered after implemented TemplateService to guard .hbs templates types.
The @Request
is not support any deconstructing function parameter from the begining.
(You can check the routes.ts generate by v6.0.1, you will find out that the key in args is still undefined)
TL;DR
Fortunately, we do have a new decorator named @RequestProp
to let you extract field from request, but currently we are not supporting any out-source type. So you have to do something like this:
import { IncomingMessage } from 'http';
handleRequest(
@RequestProp('req') req: any,
) {
// IncomingMessage is the type defined in koa's Request req filed.
const koaReq: IncomingMessage = req as IncomingMessage;
// other stuff you want
}
Did this ever work before? Or just not throw an error on build.
Did this ever work before? Or just not throw an error on build. TL;DR never work in correct way, and not throw during build cause any type.
The deconstructing function parameter was work before with casting to any from hbs. And there is none of any type check even user setup a type in controller method.
But since we introduce TemplateService, everything comes from hbs should be include with type, thus the old coincidence is not work anymore.
Is this planned to be corrected in the future? Or will it remain as is?
Is this planned to be corrected in the future? Or will it remain as is?
This is not an issue, you can consider use RequestProp
to achieve similar functionality.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
should build successfully
Current Behavior
Possible Solution
Steps to Reproduce
Context (Environment)
Version of the library: 6.1.1