An expression of type 'void' cannot be tested for truthiness

Since setItem doesn't return anything, it is complaining about using a void type in a ternary operator where a boolean is expected

You can add an if condition on this.todoitems before setItem

if (this.todoitems !== null)
    localStorage.setItem('todoitems', JSON.stringify(this.todoitems))