Array.pop() cant be undefined after if check, but typescript doenst know.

Hi, i have this snipped in my code:
if (x.length > 1) {
let entry = x.pop();
this.setSelected(0);
}
if (x.length > 1) {
let entry = x.pop();
this.setSelected(0);
}
x is of type Entry[] And pop returns Entry | undefined My question is: How can i tell typescript that it can not be the undefined branch?
Solution:
as Entry does the job
Jump to solution
3 Replies
nathanoy
nathanoy5mo ago
Oh
Solution
nathanoy
nathanoy5mo ago
as Entry does the job
nathanoy
nathanoy5mo ago
nvm then. Sorry
Want results from more Discord servers?
Add your server