Under the umi architecture: the redux definition module in the ts project has to be written every time the type definition is very troublesome
Create Redux.d.ts declaration file under typing folder
import type { Effect, Subscription, ImmerReducer } from 'umi';
declare module MyRedux {
// model
type Models<T> = {
namespace?: string;
state: T;
effects: Record<string, Effect>;
reducers: Record<string, ImmerReducer<T>>;
subscriptions?: Record<string, Subscription>;
};
}
// 导出成模块,再全局导出MyRedux,这样使用就不用再import type { Redux } from '@/typings/redux'; 了
export = MyRedux;
// 由于使用了import,此文件变成局部模块,其他地方使用只能import导入(import type { Redux } from '@/typings/redux';)才能使用
export as namespace MyRedux;
how to use
Create staff.ts in the models folder
type StaffSettingState = {
staff: Record<string, never>;
};
const StaffSettingsModel: MyRedux.Models<StaffSettingState> = {
namespace: 'staffSettingsModel',
state: {
staff: {}
},
effects: {},
reducers: {},
};
export default StaffSettingsModel;
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。