title: Make a function parameter required in TypeScript
body: <p>In the following code:</p>
  <pre><code>type NoArg = {
    (): void
  }
  
  type OneArg = {
    (x:number): void
  }
  
  let noArg: NoArg = (x:number)=&gt;{}
  let oneArg: OneArg = ()=&gt;{}
  </code></pre>
  <p>Only the first assigned generates a compiler error.  I understand why this is the case, because JavaScript allows functions to be passed with less than their complete set of possible arguments, and that’s different than saying the arguments are optional which has to do with how the function is <em>called</em> rather than how it’s <em>passed</em>. See <a href="https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters" rel="nofollow noreferrer">the FAQ</a>.</p>
  <p>But that said, is there any way to construct a version of the OneArg interface that will <em>not</em> be compatible with a zero argument function?</p>
  <p>I understand this can be done via branding or nominal typing, e.g.,</p>
  <pre><code>type OneArg = {
    (x:number): void
    _brand: “OneArg”
  }
  </code></pre>
  <p>But that, or any other type of nominal typing solution, requires doing extra work on assignment (e.g., you have to explicitly add the _brand property to the function).</p>
  <p>So my question is—is there any way to construct a type NoArg that will fail the simple assignment <code>let oneArg: OneArg = ()=&gt;{}</code>?</p>
  <p>The FAQ linked above says “There is currently not a way in TypeScript to indicate that a callback parameter must be present.“ Does that completely rule out what I want to do here?  I’m hoping it doesn’t since this isn’t a callback parameter, but perhaps the rationale is the same.</p>
  <p>UPDATE: In the comments below, a question was raised as to whether this could be achieved with a type guard test.  The answer, as far as I can tell, is no, because the type overlap means the type guard won't narrow the types.  You can see it in <a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gdhAggJwOZQLxQN4CgpQAUAHgFxwCuAtgEYTICUpUAbgPYCWAJrgL665QkKABUA7mxToseAgRLlqdZABooIUgGdgyDnFRNWnHv1wAbCMChsEUzETKVa9BhgB82fhavAJdrApOymoa2rr6rh6mAMY22lAcmvBIaPaEAGYUcNGkyVIAPuKSaIaZ2QmasLap7lBl0QB0FvrAABZQADxYAIwC9cAcNlBcidG6VHoAhsBsyIRUIABiWTlVKej5on4lOPhyAPT7IuDQqBSTyFxQrfQQajQUwA3PewQc6YSJeWjzSysMDF2cmBUGQlgoyDgUAWy2yryg-GBEDMmmgshBBDBwAhUJhK3h-FMhygzwaIgAylA2noANaVGhsNrWdJUm6oqAXaBCaBFKS4WJweILerdewjTRjDgTODTWaEGzrBj8uJWYUrABMYtG4ymMzmvmKBiAA" rel="nofollow noreferrer">this playground</a>.</p>