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

Time:11-10

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!

CodePudding user response:

you can try:

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

  • Related