Coder Social home page Coder Social logo

Comments (7)

jt-helsinki avatar jt-helsinki commented on May 8, 2024

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.

pleerock avatar pleerock commented on May 8, 2024

not sure what the problem is here, can you provide a smallest possible example so I can check it?

from routing-controllers.

telvin avatar telvin commented on May 8, 2024

@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.

MichalLytek avatar MichalLytek commented on May 8, 2024

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.

telvin avatar telvin commented on May 8, 2024

@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.

MichalLytek avatar MichalLytek commented on May 8, 2024
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.

github-actions avatar github-actions commented on May 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.