It's easy to get into a situation where the Store RootState type is flagged as Immutable because that was inferred from the useStore initialiser like this...
This is easily solved but the error message is cryptic. The solution is to be explicit about the type of your Stored RootState to establish the non-Readonly RootState as canonical, (although of course an Immutable initialiser is accepted to initially populate the Store)...
const store = useStore<AppState>(INITIAL_STATE);
There may be some way to simplify this pattern, or to harmlessly infer always the non-Readonly version of any initialising object, since Readonly is then re-applied given the Immutable annotations of the Store interface and Readonly<Readonly> collapses to Readonly so once is enough...
It's easy to get into a situation where the Store RootState type is flagged as Immutable because that was inferred from the
useStore
initialiser like this...This is easily solved but the error message is cryptic. The solution is to be explicit about the type of your Stored RootState to establish the non-Readonly RootState as canonical, (although of course an Immutable initialiser is accepted to initially populate the Store)...
There may be some way to simplify this pattern, or to harmlessly infer always the non-Readonly version of any initialising object, since Readonly is then re-applied given the Immutable annotations of the Store interface and Readonly<Readonly> collapses to Readonly so once is enough...
https://github.com/cefn/lauf/blob/main/modules/store/src/types/store.ts#L55-L74