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

373
Views
(TS - Redux) Cómo inicializar la propiedad de estado como nula: el tipo 'UserData' no se puede asignar al tipo 'null'

Tengo este error: el tipo 'UserData' no se puede asignar al tipo 'null'.

Definí la propiedad de estado del usuario como usuario: UserData | nulo; ... Así que no entiendo por qué no me permite inicializar la propiedad como nula y luego asignarle un valor similar a UserData: Error Console

 import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { UserData } from "../../types/user"; interface AppState { user: UserData | null; } const appSlice = createSlice({ name: 'app', initialState: { user: null }, reducers: { loadUserIntoApp: { reducer(state, action: PayloadAction<UserData>) { state.user = action.payload; // This is the line with an error } } } })

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe inferir la interfaz AppState al initialState

 import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { UserData } from "../../types/user"; interface AppState { user: UserData | null; } const appSlice = createSlice({ name: 'app', initialState: AppState = { user: null }, reducers: { loadUserIntoApp: { (state, action: PayloadAction<UserData>) => { //you should add the reducer like this state.user = action.payload; } } } })

ir a decumetación para más información

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!