0

I am not getting the Read-only property at the run time. Actually I am sending the PageContext object from client. Node web server (Expressjs) request does not receive the read only property.

Let me know how to resolve this issue.

/*Assume AppConfig.DefaultPageSize is 50;*/

export class PageContext {
    public PageSize: number;
    public PageNumber: number;
    public get Limit(): number {
        return this.PageSize === 0 ? AppConfig.DefaultPageSize : this.PageSize;
    };
    public get Offset(): number {
        return (this.PageNumber - 1) * this.PageSize;
    };
}

Express JS Router Code

router.post('/', (req: Request, res: Response, next: NextFunction): any => {
    let service = ServiceFactory.CreateService(UserService);
    service.GetAllUsers(req.body)
        .then((response) => {
            res.send(response);
        });
});

Service Code

GetAllUsers(req: Request<string, string>): Promise<Response<Array<any>>> {
    let users = this.userBo.GetAllUsers(req.PageContext);
    return this.GetResponse(users, req.PageContext);
}

enter image description here

Natarajan Ganapathi
  • 551
  • 1
  • 7
  • 19
  • Most likely it's not enumerable so it doesn't get serialised. Still, you need to show us the code that creates the object and sends it to the server. – Bergi May 06 '16 at 00:14
  • Is the object on the server side an actual instance of `PageContext` or just a plain object? – Bergi May 06 '16 at 00:15
  • This class available in server side. Request sent from Rest Client with plain JSON object like this `"PageContext":{ "PageSize" : 50, "PageNumber" :1 } ` – Natarajan Ganapathi May 06 '16 at 00:42
  • And how are you casting the JSON object to the class instance? Have a look at [this](http://stackoverflow.com/a/11810861/1048572) if you don't, otherwise show us your deserialisation code. – Bergi May 06 '16 at 02:18
  • Please delete that comment and [edit] your question instead where you can format code properly – Bergi May 06 '16 at 02:48

1 Answers1

0

I am not getting the Read-only property at the run time

Purely an artifact of the debug environment. You will have it just fine at runtime. Try typing in the debug console.

E.g. V8 in my chrome:

enter image description here

Code :

class Foo { get bar() { return 123 } }; var foo = new Foo(); console.log(foo.bar);
basarat
  • 261,912
  • 58
  • 460
  • 511