将根化简器传递给 configureStore 方法会使编译失败



>工具链

  • @angular/命令行
  • 界面

环境

  • 节点JS版本:8.11.3
  • 打字稿版本:2.9.3
  • 角度版本:6.1.3
  • @angular-redux/store 版本:^9.0.0
  • @angular/CLI 版本:(如果适用(:6.1.2
  • 操作系统:视窗

预期行为:

我定义了以下类型和化简器(为清楚起见,缩写(

export type LookupNum<T> = { [id: number]: T };
//-- Normalized model objects suitable for the store that use string keys --//
export interface NormalizedObjectsStr<T> {
byId: LookupNum<T>;
allIds: number[];
}
//-- Normalized model objects suitable for the store that use string keys --//
export interface NormalizedObjectsNum<T> {
byId: { [id: number]: T };
allIds: number[];
}
//-- Client side store of our data models --//
export interface ClientDataStore {
categories: NormalizedObjectsNum<Category>
attributes: NormalizedObjectsNum<Attribute>
}

// Definition of application state
export interface IAppState {
entities?: ClientDataStore;
classfnAppState?: IClassfnAppState;
}
//-- Entity reducers --//
const categoriesByIdReducer: Reducer<LookupNum<Category>, FluxStandardAction<Category | number>> = (state, action) => {
switch (action.type) {
default: { return state; }
}
}
const allCategoryIdsReducer: Reducer<number[], FluxStandardAction<Category | number>> = (state, action) => {
switch (action.type) {
default: {
return state;
}
}
}
const attributesByIdReducer: Reducer<LookupNum<Attribute>, FluxStandardAction<Category | number>> = (state, action) => {
switch (action.type) {
default: { return state; }
}
}
const allAttributesIdsReducer: Reducer<number[], FluxStandardAction<Attribute | number>> = (state, action) => {
switch (action.type) {
default: {
return state;
}
}
}

const categoriesReducer = combineReducers({
byId: categoriesByIdReducer,
allIds: allCategoryIdsReducer
});
const attributesReducer = combineReducers({
});
const entityReducer = combineReducers({
categories: categoriesReducer,
attributes: attributesReducer
});

//-- Create Root Reducer --//
export default combineReducers({
entities: entityReducer,
classfnAppState: classfnRootReducer
});

当我使用此调用配置存储时:

import appRootReducer from './reducers';
store.configureStore(
appRootReducer,
INITIAL_STATE,
[createLogger()],
devTools.isEnabled() ? [devTools.enhancer()] : []);

它应该编译并运行。

实际行为:

它不会编译时出现错误,指出减速器类型错误。 请注意,由于某种原因,它似乎丢失了客户端数据存储类型。 因为我在全州组合了多个化简器,所以似乎失去了中间接口定义。

堆栈跟踪/错误消息:

src/app/classification/classification.component.ts(14,18( 中的错误:错误 TS2339:类型"IAppStateClassfn"上不存在属性"实体"。 src/app/store/store.module.ts(33,13(: 错误 TS2345: 类型为"Reducer<{实体: { 类别: 任何; 属性: 任何; }; classfnAppState: IClassfnAppState; }, ...'不可分配给类型为"Reducer"的参数。 参数"状态"和"状态"的类型不兼容。 类型 'IAppState' 不能分配给类型 '{ entities: { categories: any; attributes: any; }; classfnAppState: IClassfnAppState; }'。 属性"entity"在类型"IAppState"中是可选的,但在类型"{ entities: { categories: any; attributes: any; }; classfnAppState: IClassfnAppState; }'中是必需的。

附加说明:

(可选(

当然,当我发布这个时,我就发现了"问题"。 该问题与错误无关。 编译器似乎对一些遗留的接口定义感到困惑,这些定义弄乱了它。 我删除了界面,它编译得很好。

相关内容

最新更新