title: String validation in Typescript
body: <p>Coming from Javascript I need some advice on how to do string validation in Typescript.</p>
  
  <p>Usually in Javascript you can just check the string as if it was a boolean, but with strong types, you get a compiler error.</p>
  
  <p>A couple of solutions I thought of, but don't really like is you could do !!myString or change the return type. Is checking for null, undefined and empty string the way to do it?</p>
  
  <p>See example:</p>
  
  <pre><code>function stringIsValid(myString: String) : Boolean {
      return myString; // compiler error
  }
  
  var isValid = stringIsValid(null);
  </code></pre>
  
  <p><a href="https://www.typescriptlang.org/play/#src=function%20stringIsValid(myString%3A%20String)%20%3A%20Boolean%20%7B%0D%0A%20%20%20%20return%20myString%3B%20%2F%2F%20compiler%20error%0D%0A%7D%0D%0A%0D%0Avar%20isValid%20%3D%20stringIsValid(null)%3B" rel="nofollow noreferrer">Playground</a></p>