Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda