Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!