/** * Generic typing for Redux async utilities * * Type definitions: * * @template I The type for a single item stored under this state key * @template E The error for failing to load a single item * @template LE The error for failing to load a collection of items * @template P An action payload */ import type { Action } from "redux"; /** * The type of the state for a single item, in a collection or as a standalone item * * @template [I=any] The type for an item returned by these selectors * @template [E=any] The error type for an item's failed load */ export interface SubstateItemData { data?: I; isLoading?: boolean; error?: E; lastUpdated?: Date; } /** * A convenience type for representing the structure of a collection's data, which is simply a * mapping of item keys to item state. The state type for a collection is a special case of * `SubstateItemData` where `I` is `ItemMap`. * * @template [I=any] The type for an item returned by these selectors * @template [E=any] The error type for an item's failed load */ export type ItemMap = { [key: string]: SubstateItemData; }; /** * A representation of the state for a collection of items. This type is a special case of * `SubstateItemData` where `I` is `ItemMap` and `E` is `LE` (which may also be `E`). In * this type definition, `I` and `E` refer to the data and error types for a single item. * * @template [I=any] The type for a single item returned by these selectors * @template [E=any] The error type for a single item's failed load * @template [LE=E] The error for failing to load the collection of items */ export type SubstateListData = SubstateItemData, LE>; /** * A Redux action compatible with these generic utilities * * @template [P=any] The payload for the action * * Future: either replace this type with the Redux-provided types or make it more compatible with * those provided types */ export interface ReduxAction

extends Action { payload: P; error?: boolean; meta: { isLoading?: boolean; [metaKey: string]: any; }; } export interface ErrorAction

extends ReduxAction

{ error: true; } export interface DataAction

extends ReduxAction

{ error: false | undefined; }