#980·rematch

TS error while using selectors inside model effects (with plugin like loading)

Author: filip-lipinski-tshCreated Nov 21, 2022Updated Nov 21, 2022

I have store configured the same as is in documentation: https://rematchjs.bootcss.com/docs/plugins/loading/, it is:

bash
export type Store = typeof store
export type Dispatch = RematchDispatch<RootModel>
export type RootState = RematchRootState<RootModel, FullModel>

model which is created: const user = createModel()({...})

Then i cannot use selectors inside a model->effects, because of error Zrzut ekranu 2022-11-21 o 15 27 16

Zrzut ekranu 2022-11-21 o 15 35 15

getUserId selector: export const getUserId = (state: RootState) => getUserData(state).id;

Error says loading is missing. Error doesn't exist if i type RootState without ExtraModels like inside EFFECTS: export type RootState = RematchRootState<RootModel>, but this is not true (i have extra plugin -> loading)

I think createModel should accept type not only RootModel, but also FullModel, it will satisfy state (seconds parameter) from model effect. I mean this:

effect:{
  myMethod: (payload, state <--THIS ONE){
  const sth = mySelector(state); // <-- not working, state is not satisfied, mySelector need RootState, but state here is equal to RematchRootState<RootModel, Record<string, never>>. 
State should be typed as RematchRootState<RootModel, FullMode> probably
}
}

To Reproduce

  1. Create store with LOADING plugin
  2. Create example model and example selector (like const mySelector = (state:RootState) => sth.
  3. Try tu use selector inside model effect.