title: How to dynamically create routes?
body: <p>I'm trying to dynamically add routes to my api by iterating over an array of objects called route groups. A route group can have many routes.</p>
  <p>Here are my types (the RouterContext type comes from Oak middleware framework):</p>
  <pre><code>// routes/mod.ts
  type Route = {
    method: string;
    path: string;
    handler: (ctx: RouterContext) =&gt; Promise&lt;void&gt;;
  };
  
  export type RouteGroup = {
    group: {
      prefix: string;
    };
    routes: Route[];
  };
  </code></pre>
  <p>Here is my router class:</p>
  <pre><code>export class Router {
    // imported Oak's Router class as oakRouter
    router: oakRouter;
  
    constructor() {
      this.router = new oakRouter({ prefix: &quot;/api&quot; });
    }
  
    register(): void {
      this._createRoutes(routeGroups);
    }
  
    private _createRoutes(routeGroups: RouteGroup[]) {
      routeGroups.forEach(({ group, routes }) =&gt; {
        routes.forEach(({ method, path, handler }) =&gt; {
          this.router[method](group.prefix + path, handler); // &lt;-- this.router[method] is underlined with an error
        });
      });
    }
  }
  </code></pre>
  <p>A typical route looks like this:</p>
  <pre><code>router.get(&quot;/&quot;, (ctx) =&gt; {
      ctx.response.body = &quot;Welcome to My Oak App.&quot;;
  });
  </code></pre>
  <p>But when I use bracket notation to dynamically add the http method that I want to use in _createRoutes(), I get the following error:</p>
  <pre><code>Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Router&lt;RouteParams, Record&lt;string, any&gt;&gt;'.
    No index signature with a parameter of type 'string' was found on type 'Router&lt;RouteParams, Record&lt;string, any&gt;&gt;'.deno-ts(7053)
  </code></pre>
  <p>How do I change the method property on the Route type from a string into a valid index signature? Is that even what I need to do?</p>