0👍
✅
this.units.find()
can return undefined
if it doesn’t find a match, which could happen if:
this.units
is initially emptythis.units
is not empty, but does not contain an element with anid
that matchesthis.selectedUnitId
You could address this by using the optional chaining operator (and defaulting to an empty string):
export default defineComponent({
computed: {
PaymentMessage() {
const found: UnitFound = this.units.find(/*...*/);
return found?.payment_message || '';
} 👆
},
})
Source:stackexchange.com