title: TypeScript type constraint expressing an optional parameter type that could exist at any position
body: <p>I'm looking to use method decorators combined with a parameter decorator.</p>
  <pre><code>class C {
    @method()
    f(a, b, @param c?: T, d?, e?) {
    }
  }
  </code></pre>
  <p>Is there a way to make the <code>@method</code> decorator a typed descriptor that only accepts functions that have <code>c?: T</code> at <strong>any</strong> position in the function signature?</p>
  <p>Right now I have something like:</p>
  <pre><code>const contexts = new WeakMap&lt;object, number&gt;();
  
  function method() {
    return &lt;F extends (...params: Array&lt;any&gt;) =&gt; any&gt;(
      target,
      key,
      descriptor: TypedPropertyDescriptor&lt;F&gt;
    ): TypedPropertyDescriptor&lt;F&gt; =&gt; {
      console.log(contexts.get(target[key]));
      return descriptor;
    }
  }
  
  function param(
    target: Object,
    key: string | symbol,
    index: number
  ) {
    const method = target[key];
    contexts.set(method, index);
  }
  </code></pre>
  <p>When I tried using tuple rest types, and used <code>T?</code> into it, it just accepted any function signature without problems.</p>
  <pre><code>[...any[], T?, ...any[]]
  </code></pre>
  <p>The main idea is to get TS to ensure that <code>@method</code> is not allowed on functions like:</p>
  <pre><code>class C {
    // Should be illegal
    @method()
    f(a, b, d?, e?) {
    }
  
    // Should be legal
    @method()
    g(a, b, @param c?: T, d?, e?) {
    }
  }
  </code></pre>
  <p>What should <code>F</code> be to get such behaviour?</p>