Tomas Gil Amoedo
Tomas Gil Amoedo

Reputation: 595

computed propert y in vue3 => object is possibly undefined TypeScript,

enter image description here

I already tried using ? after every word, I already tried something like this:

const totalNameLenght = computed(() => {
      if (userFirstnameLenght.value && userLastnameLenght.value){
        return userFirstnameLenght.value + userLastnameLenght.value
    }
  })

also tried this one:

const totalNameLenght = computed((): number | undefined => )

I don't know what else to try... how should I solve this? Thanks in advance!

Upvotes: 1

Views: 552

Answers (1)

IZEM
IZEM

Reputation: 111

you can try:

    const totalNameLength = computed(() => {
            return Number(userFirstnameLenght?.value ?? 0) + Number(userLastnameLenght?.value ?? 0)
      })

Upvotes: 1

Related Questions