title: Can typescript infer that an argument has been validated?
body: <p>I'm still learning Typescript and Javascript so please excuse me if I am missing something.</p>
  <p>The problem is as follows:</p>
  <p>Currently VSCode does not infer that I throw an error if email is undefined when calling <strong>this.defined(email)</strong>. This is due to <em>validateEmail()</em> accepting a <em>string?</em> and will not compile because it thinks it could still receive an undefined value (is my deduction at least). Is there a way to tell the compiler this is ok? or am I missing something?</p>
  <p>I would like to call Validate.validateEmail() from other classes and the problem arises in those classes as well.</p>
  <h3>Validate.ts</h3>
  <pre><code>export default class Validate {
      static validateEmail(email?: string) {
          // TODO: Test this regex properly.
          const emailRegex = new RegExp('^(([^&lt;&gt;()\[\]\\.,;:\s@&quot;]+(\.[^&lt;&gt;()\[\]\\.,;:\s@&quot;]+)*)|(&quot;.+&quot;))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
  
          this.defined(email);
          this.notEmpty(email);
  
          if (!emailRegex.test(email)) {
              throw new SyntaxError(&quot;The email entered is not valid&quot;);
          }
      }
  
      static defined(text?: string) {
          if (!text) {
              throw new SyntaxError(&quot;The text recieved was not defined.&quot;);
          }
      }
  
      static notEmpty(text: string) {
          if (text.length &lt; 1) {
              throw new SyntaxError(&quot;The text entered is empty.&quot;);
          }
      }
  }
  </code></pre>