title: Typescript: Optional function arguments cause problems in function body
body: <p>I am new to TypeScript and have a little problem with an optional argument in a function. I got the following error in Visual Studio Code for the <code>query</code> argument (see screen shot). I really don't understand this error, because I defined the type as <code>string</code>. So why do I get this error?</p>
  
  <blockquote>
    <p>message: 'Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/33kNy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/33kNy.png" alt="Screen shot error in VS Code"></a></p>
  
  <pre><code>public async fetchPut&lt;T&gt;(requestURL: string, body: TBody, query?: string): Promise&lt;T&gt; {
  
      const finalRequestOption: IFetchOption = Object.assign({
          method: 'PUT',
          headers: this.headers
      }, { body });
  
      const response: Response = await this.httpClient.fetch(
              this.getRequestURL(requestURL, query), 
              finalRequestOption);
  
      return response.json();
  }
  </code></pre>