title: How to add an optional parameter to a decorator in TypeScript?
body: <p>I want to create a field decorator that optionally can take an argument.
  The argument should contain any of the following values: nothing, a boolean or a function.
  I know how to do this, but I'm not 100% happy with the result:</p>
  
  <pre><code>export class TestClass{
  
     @Required(isRequired) 
     public testField: string;
  
  }
  
  export function isRequired():boolean{
     ... some validation logic, maybe depending on other fields...
     return result;
  }
  </code></pre>
  
  <p>Implementation of @Required:</p>
  
  <pre><code>export function Required(expression?: boolean|Function): Function {
      return (target: any, key: string) =&gt; {
          if (expression === null || typeof expression == 'undefined') {
              expression = true;
          }
          console.log("Required found: " + expression, ":", target, key);
          ... register the field and its validation expression for later usage
      }
  }
  </code></pre>
  
  <p>So this works fine, but when I do not want to add an expression (and thus use the defaulted "true" expression) I want to be able to write it like this:</p>
  
  <pre><code>class TestClass{
  
     @Required
     public testField: string;
  
  }
  </code></pre>
  
  <p>I get a TypeScript error (TS1240) saying:</p>
  
  <blockquote>
    <p>Unable to resolve signature of property decorator when called as an
    expression.   Supplied parameters do not match any signature of call
    target</p>
  </blockquote>
  
  <p>So I need to write @Required()</p>
  
  <pre><code>class TestClass{
  
     @Required()
     public testField: string;
  
  }
  </code></pre>
  
  <p>Is it possible to write a decorator implementation that takes optionally an argument and when that argument is not specified there is no need to add the "()" ?</p>