title: Typescript decorator - accepts too few arguments to be used as a decorator here
body: <p>I am trying to write a decorator that accepts a method and throws an error if the method did not complete in the specified timeout (specified using the method arguments). Not specifying a timeout should result in the method running as if the argument is not there.</p>
  
  <pre><code>export const setMethodTimeout = (): Function =&gt; {
    return function(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) {
      const context = this;
      const args: DecoratorArgumentType = arguments;
      if (args.timeout) {
        const timer = setTimeout(() =&gt; {
          throw new Error('The method did not finish before the specified timeout.');
        }, args.timeout);
        const originalMethod = descriptor.value;
        descriptor.value = function() {
          originalMethod
            .apply(context, args)
            .then((result: any) =&gt; {
              clearTimeout(timer);
              return result;
            })
            .catch((e: Error) =&gt; {
              throw e;
            });
        };
      }
      return descriptor;
    };
  };
  </code></pre>
  
  <p>Now when I try to use this decorator on my class method:</p>
  
  <pre><code>@setMethodTimeout
  public async getMap(params: GetMapParams, api: ApiType, reqConfig?: RequestConfiguration): Promise&lt;Blob&gt; {
     //...
  }
  </code></pre>
  
  <p>I get the following typescript error:</p>
  
  <blockquote>
    <p>‘setMethodTimeout’ accepts too few arguments to be used as a decorator here. Did you mean to call it first and write ‘@setMethodTimeout()’?</p>
  </blockquote>
  
  <p>Why is this happening?</p>