Experiencing TypeScript mismatches between preloadedState and configureStore #5215
Unanswered
binarykitchen
asked this question in
Q&A
Replies: 1 comment 6 replies
-
|
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Good evening again,
Great discussions before. I'm getting closer, although experiencing some TypeScript mismatches. The
configureStorefn is not accepting the typings of mypreloadedState:Error:
To reproduce:
git clone git@github.com:binarykitchen/videomail-recorder.gitnpm installnpm run typesThe
configureStorefn believes the preloadedState can be undefined, which is wrong:https://github.com/binarykitchen/videomail-recorder/blob/main/src/root/store.ts#L7
In my case, the preloaded state should be always defined, never undefined. Running the library with undefined options is a no-go. So, I believe, the problem is how to extract the correct type for the preloadedState from root reducers.
What I do for now:
See: https://github.com/binarykitchen/videomail-recorder/blob/main/src/root/types.ts#L6
Because it's accessing an array I reckon, that's why
configureStorebelieves it can be undefined.I understand that the state is always at index zero, although this conflicts with TypeScript.
Is there a better recipe to define the type of the root state based on root reducers rather than using an array index?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions