Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
filip-lipinski-tsh opened this issue Nov 21, 2022 · 1 comment

Comments

@filip-lipinski-tsh
Copy link

filip-lipinski-tsh commented Nov 21, 2022

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.
@filip-lipinski-tsh filip-lipinski-tsh changed the title TS error while using selectors inside model (with plugin like loading) TS error while using selectors inside model effects (with plugin like loading) Nov 21, 2022
@filip-lipinski-tsh
Copy link
Author

Zrzut ekranu 2022-11-21 o 15 58 56
To RematchRootState there is only TModels passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy