-3

The same question exists for javascript but I don't think the solutions listed there apply for typescript.

Firstly I've an object of type express.Request and I want to debug its body member:

function test(req : express.Request, res :express.Response, next:(err:any)=>void) {


  req.defineProperty(body, 'someProp', { //Property 'defineProperty' does not exist on type 'Request'.
    get: function () {
        return req._body;
    },

    set: function (value) {
        debugger; // sets breakpoint
        obj._someProp = value;
    }
});
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66

1 Answers1

1

The method you are looking for is called Object.defineProperty and it takes the object on which to define the property as the first argument. The proper usage would be something like this:

function test(req: express.Request, res: express.Response, next: (err: any) => void) {

    Object.defineProperty(req, 'body', {
        get: function () {
            return req._body;
        },

        set: function (value) {
            debugger; // sets breakpoint
            req._body = value;
        }
    });
}
Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75