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

182
Visualizações
return full class with reducer statement

I'm getting the error:

"Type '{ permissions: any; avatarUrl: string; email: string; calendarStatus: string; roleID: number; lastLoginDate: DateType; mfa: boolean; availability: string | null; outOfOffice: any[]; ... 4 more ...; name: string; }' is missing the following properties from type 'User': role, subtitle, searchField, link, and 3 more.ts(2740)"

with the following function:

const reducer = (state: User, action: { type: string, value: any | object }): User => {
  switch (action.type) {
    case 'roleChange':
      return { ...state, ...action.value }
    case 'permissionsChange':
      return { ...state, permissions: { ...state.permissions, ...action.value } }
    default:
      break
  }
  return state
}

The problem is with this line:

return { ...state, permissions: { ...state.permissions, ...action.value } }

My intention is return the full class, not a partial. I'm aware I can type it to return a Partial User, but this fix makes other parts of my code not workable, as I reference certain attributes on the User class.

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

0

You're casting the action.value instead of assigning a value to a property. It should look like this.

 const reducer = (state: User, action: { type: string, value: any | object }): User => { switch (action.type) { case 'roleChange': return { ...state, ...action.value } case 'permissionsChange': return { ...state, permissions: action.value } default: break } return state }

Or if you know the field within the permissions you want to update

 const reducer = (state: User, action: { type: string, value: any | object }): User => { switch (action.type) { case 'roleChange': return { ...state, ...action.value } case 'permissionsChange': return { ...state, permissions: { ...state.permissions, someField: action.value } } default: break } return state }
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