In my project using Typescript 2.0 with strict null checks, I am working with an array:
private _timers: ITimer[]
and have the following if statement:
if(this._timers.length > 0){
this._timers.shift().stop();
}
However, I encounter a compile error stating:
Object is possibly 'undefined'
Is there a way to assure the compiler that it will not be undefined?
An alternative approach would be:
const timer = this._timers.shift();
if(timer){
timer.stop();
}
Nevertheless, this solution may seem overly verbose and use an unnecessary variable just to address the typing constraints.
Thank you!