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

166
Visualizações
I cannot define my state in reduxjs/toolkit as Array

I need to define in my app state as empty Array initially and later it will be an Array of objects.

I have object type defined like below:

export type LuxmedBenefitUserType= {
  id: number;
  name: string;
  lastName: string;
  profileName: string;
  contractForm: string;
  userRelation: string;
  offerType: string;
  totalPrice: number;
  employerCost: number;
  employeeCost: number;
};

Then I define createSlice initial state as below.

export const addEditLuxmedBenefitSystemsSlice = createSlice({
  name: 'addEditLuxmedSlice',
  initialState: [] as LuxmedBenefitUserType[],
  reducers: {
    addEditBenefits: (state, action) => {
      const {id} = action.payload;
      if(!state) {state.push(action.payload)};
      if(state) {state.map = (user)=>{
    user.id === id && return action.payload
  }}; 
    },
  },
});

But with this I cannot procee with .push , it throws me an error :

any
Property 'push' does not exist on type 'never'.

Can You please let me know what I do wrong here and that state will allow me to use .push method ?

thanks

about 4 years ago · Santiago Trujillo
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