title: How to check for null value inline and throw an error in typescript?
body: <p>In C# I can write code to check for null references and in case throw a custom exception, example:</p>
  
  <pre><code>var myValue = (someObject?.SomeProperty ?? throw new Exception("...")).SomeProperty;
  </code></pre>
  
  <p>In recent updates TypeScript introduced the null coalescing operator ?? but using it like the above statement produces a compilation error.
  Is there some similar allowed syntax in TypeScript?</p>
  
  <hr>
  
  <p>To clarify, the desired behavior is achieved with the following code:</p>
  
  <pre><code>  if(someObject?.someProperty == null) {
      throw new Error("...");
    }
  
    var myValue = someObject.someProperty.someProperty;
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>  var myValue = someObject?.someProperty.someProperty;
  </code></pre>
  
  <p>works logically ok but throws a less meaningful exception.</p>