title: How does Typescript Annotation Scan Works?
body: <p>I am working on a project where i have implemented annotations to do routing for a express api app. But the I am getting a empty route list at run-time.</p>
  
  <p>I have tried many resources but could not figure out how to do it.</p>
  
  <pre><code>// RouteService File
  export const routes: {
      path: string,
      router: string[]
  }[] = [];
  
  export function GetDynamicRoutes(): string[] {
    let router: string[] = [];
    routes.forEach(route =&gt; {
      router = router.concat(route.router);
    })
    return router;
  }
  
  // Decorators File
  import { routes } from "../service/route.service";
  import { AbstractController } from "../controller/abstract.controller";
  
  export function Route(path: string) {
      return function (constructor: Function) {
          routes.push({
              path,
              router: constructor.prototype.router
          });
      }
  }
  
  export function RouteRequest(path?: string) {
      return function (target: Object, key: string | symbol,
          descriptor: PropertyDescriptor) {
          if (target.isPrototypeOf(AbstractController)) {
              const router = (target as AbstractController).router;
              const endpoint = path ? path : key.toString();
  
              router.push(endpoint);
          }
      }
  }
  
  // AbstractController file
  export class AbstractController {
    public router: string[];
  
    constructor() {
      this.router = [];
    }
  }
  
  // TestController File
  import { Route, RouteRequest } from "../decorator/route.decorator";
  import { AbstractController } from "./abstract.controller";
  
  @Route('test')
  export class TestController extends AbstractController {
      @RouteRequest()
      helloWorld() {
          console.log('inside-hello-world');
      }
  }
  
  // Main File
  import { GetDynamicRoutes } from "./service/route.service";
  
  function main() {
      const routes = GetDynamicRoutes();
      console.log(routes);
  }
  main();
  </code></pre>
  
  <p>Here is a Sample Code. Commented are separated files. All imports are done.</p>
  
  <p><a href="https://codesandbox.io/s/youthful-goldwasser-t8byo?fontsize=14&amp;hidenavigation=1&amp;theme=dark" rel="nofollow noreferrer"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="Edit youthful-goldwasser-t8byo"></a></p>