Are there any idioms in typescript to define properties to methods in a class inline with the method definition?
I'm looking for something similar to .NET attributes.
Here's an example of what I've got so far
class FooController {
foo(req: express.Request, res: express.Response) {
res.send(JSON.stringify({ loc: 'FooController::foo 2 here '+req.params.fooId }));
}
bar(req: express.Request, res: express.Response) {
res.send(JSON.stringify({ loc: 'FooController::bar here' }));
}
}
FooController.prototype.foo['route'] = '/foo/:fooId';
FooController.prototype.foo['verb'] = 'get';
FooController.prototype.bar['route'] = '/bar';
FooController.prototype.bar['verb'] = 'post';
where a different function will consume FooController and interrogate the method attributes to set up a routing table before any of the FooController methods are invoked.
I don't like the distance between my method definitions and my property definitions, especially as my methods get larger and supporting functions sit in between the two.
Is there anything better I can do here? If there are different language features I should be using to express this other than properties, I'm open to that. I'm especially interested if the solution retains type safety.
I did review build a function object with properties in typescript but I don't think the solutions in there are a good match because of the late binding and object method requirements.
I'm using typescript compiler version 1.0.3 with Visual Studio 2013 Update 3.