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

851
Views
Redux-Toolkit extraReducers listed after reducers causes issues (TS2322 Error)

Problem

I am using Redux-Toolkit and I am having an issue with the code below. When extraReducers is omitted, my code works fine. When extraReducers is listed after reducers, I encounter an error (shown below). When extraReducers is listed before reducers, my code works fine. What am I missing here?

type Item = { id: string, name: string }

export const itemsAdapter = createEntityAdapter<Item>();
const initialState = itemsAdapter.getInitialState();

export const slice = createSlice({
  name: 'items',
  initialState,
  reducers: {  
    itemsAdded(state, action: PayloadAction<{ items: Item[] }>) {
      itemsAdapter.setAll(state, action.payload.items);
    }, 
  },
  extraReducers: (builder) => { /*  },,
});

Error Message

TS2322: Type '(state: WritableDraft<EntityState<Item>>, action: { payload: { items: Item[]; }; type: string; }) => void' is not assignable to type 'CaseReducer<WritableDraft<EntityState<Item>> | undefined, { payload: any; type: string; }> | CaseReducerWithPrepare<WritableDraft<EntityState<Item>> | undefined, PayloadAction<...>>'.
  Type '(state: WritableDraft<EntityState<Item>>, action: { payload: { items: Item[]; }; type: string; }) => void' is not assignable to type 'CaseReducer<WritableDraft<EntityState<Item>> | undefined, { payload: any; type: string; }>'.
    Types of parameters 'state' and 'state' are incompatible.
      Type 'WritableDraft<WritableDraft<EntityState<Item>>> | undefined' is not assignable to type 'WritableDraft<EntityState<Item>>'.
        Type 'undefined' is not assignable to type 'WritableDraft<EntityState<Item>>'.
about 4 years ago · Juan Pablo Isaza
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!