UNPKG

3.34 kBTypeScriptView Raw
1import { ActionReducer, Selector } from './models';
2import { FeatureSelector, NestedSelectors } from './feature_creator_models';
3export interface FeatureConfig<FeatureName extends string, FeatureState> {
4 name: FeatureName;
5 reducer: ActionReducer<FeatureState>;
6}
7declare type Feature<AppState extends Record<string, any>, FeatureName extends keyof AppState & string, FeatureState extends AppState[FeatureName]> = FeatureConfig<FeatureName, FeatureState> & BaseSelectors<AppState, FeatureName, FeatureState>;
8declare type FeatureWithExtraSelectors<FeatureName extends string, FeatureState, ExtraSelectors extends SelectorsDictionary> = string extends keyof ExtraSelectors ? Feature<Record<string, any>, FeatureName, FeatureState> : Omit<Feature<Record<string, any>, FeatureName, FeatureState>, keyof ExtraSelectors> & ExtraSelectors;
9declare type BaseSelectors<AppState extends Record<string, any>, FeatureName extends keyof AppState & string, FeatureState extends AppState[FeatureName]> = FeatureSelector<AppState, FeatureName, FeatureState> & NestedSelectors<AppState, FeatureState>;
10declare type SelectorsDictionary = Record<string, Selector<Record<string, any>, unknown>>;
11declare type ExtraSelectorsFactory<FeatureName extends string, FeatureState, ExtraSelectors extends SelectorsDictionary> = (baseSelectors: BaseSelectors<Record<string, any>, FeatureName, FeatureState>) => ExtraSelectors;
12declare type NotAllowedFeatureStateCheck<FeatureState> = FeatureState extends Required<FeatureState> ? unknown : 'optional properties are not allowed in the feature state';
13/**
14 * Creates a feature object with extra selectors.
15 *
16 * @param featureConfig An object that contains a feature name, a feature
17 * reducer, and extra selectors factory.
18 * @returns An object that contains a feature name, a feature reducer,
19 * a feature selector, a selector for each feature state property, and
20 * extra selectors.
21 */
22export declare function createFeature<FeatureName extends string, FeatureState, ExtraSelectors extends SelectorsDictionary>(featureConfig: FeatureConfig<FeatureName, FeatureState> & {
23 extraSelectors: ExtraSelectorsFactory<FeatureName, FeatureState, ExtraSelectors>;
24} & NotAllowedFeatureStateCheck<FeatureState>): FeatureWithExtraSelectors<FeatureName, FeatureState, ExtraSelectors>;
25/**
26 * Creates a feature object.
27 *
28 * @param featureConfig An object that contains a feature name and a feature
29 * reducer.
30 * @returns An object that contains a feature name, a feature reducer,
31 * a feature selector, and a selector for each feature state property.
32 */
33export declare function createFeature<FeatureName extends string, FeatureState>(featureConfig: FeatureConfig<FeatureName, FeatureState> & NotAllowedFeatureStateCheck<FeatureState>): Feature<Record<string, any>, FeatureName, FeatureState>;
34/**
35 * @deprecated Use the `createFeature` signature without root state instead.
36 * For more info see: https://github.com/ngrx/platform/issues/3737
37 */
38export declare function createFeature<AppState extends Record<string, any>, FeatureName extends keyof AppState & string = keyof AppState & string, FeatureState extends AppState[FeatureName] = AppState[FeatureName]>(featureConfig: FeatureConfig<FeatureName, FeatureState> & NotAllowedFeatureStateCheck<FeatureState>): Feature<AppState, FeatureName, FeatureState>;
39export {};