If you need this call more often it's possible to declare it globally:
interface Array {
last(): T | undefined;
}
if (!Array.prototype.last) {
Array.prototype.last = function () {
if (!this.length) {
return undefined;
}
return this[this.length - 1];
};
}
then you can just call
items.last()