Skip to main content

foundation-redux.rootstatefromslices

Home > @genesislcap/foundation-redux > RootStateFromSlices

RootStateFromSlices type​

Extracts the root state type from an array of slices.

Signature:

export type RootStateFromSlices<S extends SliceArray> = {
[K in S[number]['name']]: Extract<S[number], {
name: K;
}> extends Slice<infer State> ? State : never;
};

References: SliceArray, Slice

Remarks​

This utility type maps over the slice names and extracts the state type for each slice. The resulting type represents the complete state structure of your Redux store.

Example​

const slices = [userSlice, cartSlice];
type RootState = RootStateFromSlices<typeof slices>;
// Result: { user: UserState, cart: CartState }