<p dir="auto">It would be great if the <a href="https://msdn.microsoft.com/library/dn986595.aspx" rel="nofollow">C# null-conditional operator</a> <code class="notranslate">?.</code> could be included in TypeScript.</p>
<p dir="auto">Actually it might be more accurate to call it undefined-or-null-conditional operator in TypeScript.</p>
<p dir="auto">The expected behavior for <code class="notranslate">a?.b</code> is to return <code class="notranslate">a</code> when <code class="notranslate">a</code> is <code class="notranslate">undefined</code> or <code class="notranslate">null</code> else <code class="notranslate">a.b</code>.</p>
<p dir="auto"><strong>Typescript</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var n1: number = 5;
var n2: number = undefined;
var b: boolean = false;

console.log(n1?.toString() || ''); // '5'
console.log(n2?.toString() || ''); // ''
console.log(b?.toString() || ''); // 'false'"><pre class="notranslate"><code class="notranslate">var n1: number = 5;
var n2: number = undefined;
var b: boolean = false;

console.log(n1?.toString() || ''); // '5'
console.log(n2?.toString() || ''); // ''
console.log(b?.toString() || ''); // 'false'
</code></pre></div>
<p dir="auto"><strong>Javascript</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var n1 = 5;
var n2 = undefined;
var b = false;
console.log(n1 == null ? n1 : n1.toString() || ''); // '5'
console.log(n2 == null ? n2 : n2.toString() || ''); // ''
console.log(b == null ? b : b.toString() || ''); // 'false'"><pre class="notranslate"><code class="notranslate">var n1 = 5;
var n2 = undefined;
var b = false;
console.log(n1 == null ? n1 : n1.toString() || ''); // '5'
console.log(n2 == null ? n2 : n2.toString() || ''); // ''
console.log(b == null ? b : b.toString() || ''); // 'false'
</code></pre></div>
<p dir="auto">See <a href="http://stackoverflow.com/questions/2647867/how-to-determine-if-variable-is-undefined-or-null" rel="nofollow">this thread</a> for the null checking explanation.</p>
<p dir="auto">It should be possible to chain null-conditional operators:</p>
<p dir="auto"><strong>Typescript</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var x1 = null;
var x2 = {};
var x3 = { v: undefined };
var x4 = { v: 5 };
console.log(x1?.v?.toString() || ''); // ''
console.log(x2?.v?.toString() || ''); // ''
console.log(x3?.v?.toString() || ''); // ''
console.log(x4?.v?.toString() || ''); // '5'
console.log(x4?.v?.w?.toString() || ''); // ''"><pre class="notranslate"><code class="notranslate">var x1 = null;
var x2 = {};
var x3 = { v: undefined };
var x4 = { v: 5 };
console.log(x1?.v?.toString() || ''); // ''
console.log(x2?.v?.toString() || ''); // ''
console.log(x3?.v?.toString() || ''); // ''
console.log(x4?.v?.toString() || ''); // '5'
console.log(x4?.v?.w?.toString() || ''); // ''
</code></pre></div>
<p dir="auto"><a href="http://stackoverflow.com/questions/37386265/generic-return-type-of-function-in-typescript" rel="nofollow">http://stackoverflow.com/questions/37386265/generic-return-type-of-function-in-typescript</a></p>

<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.7.5 / 1.8.0-beta / nightly (1.9.0-dev.20160217)</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// A self-contained demonstration of the problem follows...
"><pre class="notranslate"><span class="pl-c">// A self-contained demonstration of the problem follows...</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<p dir="auto"><strong>Actual behavior:</strong></p>