Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Vue 3 with TypeScript cannot read properties

I have some problems with Vue 3 and TypeScript. I had one property 'user' that was a string, and I returned object from backend, so ofc it broke, I changed the property type to object but I'm still receiving error like:

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'email')

This is how I'm calling it in front.

{{ item.user.email }}

It's actually in v-for, real property is items (array ofc)

So in props it was String, and I changed it to object, like so:

 props: {
    user: {
      type: Object,
      default: undefined
    },

And I have transformer like:

const  gTransformer = (data: GResponse[]): CARD[]  => {
      console.info(data)
      return data.map((element, index): CARD => ({
          id: element.id,
          status: element.status,
          created_at: moment(element.created_at).toDate(),
          updated_at: moment(element.updated_at).toDate(),
          user: element.user
        })
      )

}

And this is how GResponse interface looks like:

export interface GResponse {
  id: number;
  status: number;
  user: any;
  created_at: string,
  updated_at: string
}

and CARD interface is like:

export interface GiftCard {
  id: number;
  status: SomeEnum,
  user: any;
  created_at: Date,
  updated_at: Date
}

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Define your prop types for TypeScript in Vue3 Options API like this: source

import { PropType } from 'vue'
...
props: {
  user: undefined as PropType<Object | undefined>
},
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda