Comments (7)
OK, if I add change the controller function signature to entry(@Req() request: express.Request, @Res() response: express.Response)
it works ok. However why does it compile in this way? Is this a decorator problem?
from routing-controllers.
not sure what the problem is here, can you provide a smallest possible example so I can check it?
from routing-controllers.
@paistipoikka I got the same issue today. I figured out that is the typings issue in Typescript compiler, it misunderstands the Request that is imported from express in following line and the decorator @Req
import {Request} from "express";
Therefore, instead of compiling to "params_1.Req()", the outcome could be 'express_1.Req()' without any declare on the generated file.
Solution is setting 'any' type to Request or, set with namespace like express.Request.
from routing-controllers.
How Req
can become Request
? Can you show me the code sample? I always do sth like this:
import { Request, Response } from "express";
import { Controller, Get, Req, Res } from "routing-controllers";
@Controller("/test")
export class TestController {
@Get()
test(@Req() req: Request, @Res() res: Response) {
res.send(req.param.id);
}
}
from routing-controllers.
@19majkel94 My code is exactly the same with you. I am not saying this is the bug of routing-controllers, either is @Req decorator. I think there could be some human mistakes when trying to migrate from older version of routing-controller to v.0.7.0. I was doing that, migrating to v.0.7.0, after package updated and things went wrong. There was an personal update on another package with typings, and it accidentally affected express in irrelevant situation.
The generated file which caused error contains following lines
__decorate([
methods_1.Get("/fb/webhook"),
methods_1.Post("/fb/webhook"),
__param(0, express_1.Req()), // which is wrong, express_1 never declares on the file, instead the correct one should be param_1.Req()
from routing-controllers.
import { Get, JsonController, Req, Res } from "routing-controllers"
import { Request, Response } from "express"
@JsonController()
class GithubController {
@Get("/raw/:id")
rawExpress(@Req() req: Request, @Res() res: Response) {
res.json({ id: req.params.id })
}
}
__decorate([
routing_controllers_1.Get("/raw/:id"),
__param(0, routing_controllers_1.Req()), __param(1, routing_controllers_1.Res()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], GithubController.prototype, "rawExpress", null);
You have something wrong with your codebase, maybe weird import from inside of routing-controllers package or sth like /// <reference path='../typings/index.d.ts' />
. I am closing this issue again 😉
from routing-controllers.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from routing-controllers.
Related Issues (20)
- fix: global middlewares (re)registered each time useExpressServer is called HOT 3
- question: @Param not type casted HOT 21
- question: building the code looks for Koa, while I'm only using Express HOT 8
- fix: class-validator does not work on last version of RC HOT 9
- fix: <Injected Response object is undefined> HOT 1
- question: @Get path with literal and variable HOT 3
- feature: <how make sub folder controllers> how make sub folder controllers HOT 2
- fix: jsdoc for Put http method, it mentions POST http method
- fix: TypeDI do not inject service HOT 1
- Annotate return type of `createExpressServer` with more narrow type HOT 1
- `cors: true` causes "Cannot set headers after they are sent to the client" error HOT 3
- fix: Global middlewares are not used if route prefix doesn't start with a slash ("/")
- fix: TypeError this.targetType.toLowerCase is not a function HOT 3
- fix: import statements should not affect the route matching order
- Can we create multiple paths for the same controller function? HOT 7
- fix: CJS being imported instead of ESM when trying to load controllers from directory import HOT 4
- feature: Allow to use `app.use(createExpressRouter())` instead of `useExpressServer(app)` HOT 6
- question: Routes with path parameters continue middleware chain (but those without, don't)? HOT 5
- feature: Dynamic route HOT 5
- feature: Introduce Generics to CurrentUserChecker for Enhanced Type Safety HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routing-controllers.