UNPKG

@redux-ts-starter-kit/slice

Version:
57 lines (56 loc) 3.33 kB
import type { NestedObject } from './types'; import type { ActionMap, ActionCreatorsMap, Selectors, Reducer, CasesBase } from './slice'; declare type ArgOf<Fn> = Fn extends (o: infer O, ...g: any) => any ? O : never; export declare const makeComputedSelectors: <ComputedMap extends { [s: string]: (s: any) => any; }>(selectors: ComputedMap) => ComputedMap; export declare function reMapSelectors<P extends string[] & { length: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; }, SelectorMap extends { [s: string]: (s: any) => any; }, State extends any, Obj extends NestedObject<P, 0, any>>(selectors: SelectorMap, ...paths: P): ReMappedSelectors<P, SelectorMap>; export declare function reMapSelectors<P extends string[] & { length: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; }, Selector extends (s: any) => any, State extends any, Obj extends NestedObject<P, 0, any>>(selector: Selector, ...paths: P): ReMappedSelector<P, Selector>; export declare type ReMappedSelectors<P extends string[], Selects extends { [s: string]: (state: any) => any; }> = { [K in keyof Selects]: ReMappedSelector<P, Selects[K]>; }; export declare type ReMappedSelector<P extends string[], Select extends (state: any) => any> = P extends [''] ? (state: ArgOf<Select>) => ReturnType<Select> : (state: NestedObject<P, 0, ArgOf<Select>>) => ReturnType<Select>; export interface MapSelectorsTo<SelectorMap extends { [s: string]: (state: any) => any; }> { <P extends string[] & { length: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; }>(p0: '', ...paths: P): ReMappedSelectors<P, SelectorMap>; <P extends string[] & { length: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; }>(...paths: P): ReMappedSelectors<P, SelectorMap>; } export declare function makeReMapableSelectors<SelectorMap extends { [s: string]: (s: any) => any; }>(selectors: SelectorMap): MapSelectorsTo<SelectorMap>; export declare function makeReMapableSelectors<SelectorMap extends { [s: string]: (s: any) => any; }, ComputedMap extends { [s: string]: (s: any) => any; }, S>(selectors: SelectorMap, computed: ComputedMap): MapSelectorsTo<SelectorMap & ComputedMap>; export declare const makeActionCreators: <Actions extends ActionMap<any>, TypeOverrides extends { [K in keyof Actions]?: string | undefined; }, SliceName extends string>(actionKeys: Extract<keyof Actions, string>[], typeOverrides?: TypeOverrides, name?: SliceName) => ActionCreatorsMap<Actions, TypeOverrides, "">; export declare const makeReducer: <Cases extends CasesBase<S>, S, TyO extends { [K in keyof Cases]?: string | undefined; }, SliceName extends string>(initialState: S, casesInput: Cases, typeOverrides?: TyO, name?: SliceName) => Reducer<S, import("./types").AnyAction<string>>; export interface MakeSelectors { <SliceState>(initialState: SliceState, paths?: ''): Selectors<SliceState>; <SliceState, P extends string[]>(initialState: SliceState, ...paths: P): ReMappedSelectors<P, Selectors<SliceState>>; } export declare const makeSelectors: MakeSelectors; export declare type CreateNameSpace<SS, Ax> = <Sl extends string>(slice: Sl) => { sliceReducer: Reducer<SS> & { toString: () => Sl; }; sliceActions: { [K in keyof Ax]: Ax[K] & { slice: Sl; }; }; }; export {};