Я пытаюсь понять причину и исправить ошибку типа в моем неизменном js root редукторе. Похоже, что мой initialStateRecord
не выводит типы Immutable.Record. Но заставить его работать правильно - это за пределами моего ограниченного опыта.
код
import { combineReducers } from 'redux-immutable';
import Immutable from 'immutable';
const initialState = Immutable.Map<string, any>();
const reducer = (state = initialState) => state;
const UserStore = {
initialState,
reducer,
};
interface IStateRecord {
user: ReturnType<typeof UserStore.reducer>;
}
const initialStateRecord = Immutable.Record<IStateRecord>({
user: UserStore.initialState,
});
export default combineReducers<IStateRecord>(
{
user: UserStore.reducer,
},
initialStateRecord, // <= getting a type error here
);
ошибка
Argument of type 'Factory<IStateRecord>' is not assignable to parameter of type '() => Indexed<IStateRecord>'. Type 'Record<IStateRecord> & Readonly<IStateRecord>' is missing the following properties from type 'Indexed<IStateRecord>': toArray, fromEntrySeq, interpose, interleave, and 71 more.
index.d.ts декларации для
combineReducers
import { ReducersMapObject, Reducer, Action } from 'redux';
import { Collection } from 'immutable';
export declare function combineReducers<S, A extends Action, T>(reducers: ReducersMapObject<S, A>, getDefaultState?: () => Collection.Keyed<T, S>): Reducer<S, A>;
export declare function combineReducers<S, A extends Action>(reducers: ReducersMapObject<S, A>, getDefaultState?: () => Collection.Indexed<S>): Reducer<S, A>;
export declare function combineReducers<S>(reducers: ReducersMapObject<S, any>, getDefaultState?: () => Collection.Indexed<S>): Reducer<S>;