10 Apr 2017

Anonymous decorators

article lead

I found bug in angular2-template-loader. It turned out that's known bug you can find here

Author proposes to use AST to solve it. I think it's overkill for such problem. One of solutions I came up with was to use Javascript itself to solve it. Like anonymous decorator.

You can actually write anonymous decorators in Javascript:

@(function() {
  return function(constructor: Function) {
    console.log("test");
  };
})()
class Test {}

var a = new Test();

It prints test on the console. It's really amazing how flexible is this language.