Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

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

@filip-lipinski-tsh

Description

@filip-lipinski-tsh

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions