Dealing with Array shift return type in Typescript 2.0 with strict null checks
<p>In my Typescript 2.0 project with strict null checks I have an array:</p>

<p><code>private _timers: ITimer[]</code></p>

<p>and an if statement:</p>

<pre><code>if(this._timers.length &gt; 0){
  this._timers.shift().stop();
}
</code></pre>

<p>but I get a compile error:</p>

<p><code>Object is possibly 'undefined'</code></p>

<p>How can I convince the compiler that it's not undefined?</p>

<p>I can get round it like this:</p>

<pre><code>const timer = this._timers.shift();
if(timer){
  timer.stop();
}
</code></pre>

<p>but that seems a bit too verbose and a needless use of a variable just to get round the typing constraints.</p>

<p>Thanks</p>