title: How to explicitly type a generic function in TypeScript?
body: <h2>Problem</h2>
  <p>I have the following generic function type:</p>
  <pre><code>type Validator&lt;TInput, TOutput extends TInput&gt; = (value: TInput) =&gt; Validated&lt;TOutput&gt;;
  </code></pre>
  <p>Now I want to implement this type, so I did the following:</p>
  <pre><code>const isNotNull: Validator&lt;T | null, T&gt; = &lt;T&gt;(value: T | null): Validated&lt;T&gt; =&gt; {
      // Implementation here
  };
  </code></pre>
  <p>This doesn't work because <code>T</code> is used before it's defined.</p>
  <p>I know I can infer the type of <code>isNotNull</code> but I want to <strong>explicitly</strong> declare it as <code>Validator</code> as a constraint. How do I do this?</p>
  <hr />
  <h2>Context</h2>
  <p>This <code>Validator</code> type will be used as a function argument, like the following:</p>
  <pre><code>function validate&lt;TInput, TOutput&gt;(
      value: TInput,
      validator: Validator&lt;TInput, TOutput&gt;
  ): TOutput {}
  </code></pre>
  <p><em>Of course in reality there is no need for this function. The real scenario is more complex, but I've stripped it down to the minimum.</em></p>
  <p>This is why <code>Validator</code> must be generic.</p>