[Vuejs]-Object is possibly 'undefined' in Vuex mutation with TypeScript

1👍

state.board.lists.find(list => list.id === idList).cards.unshift(card)

The specific list may not be found. So you won’t be able to pick cards from it.

const list = state.board.lists.find(list => list.id === idList)

if (!list) {
    // do something
    return
}

// list found so return
return list.cards.unshift(card)
👤Adam

Leave a comment