共计 741 个字符,预计需要花费 2 分钟才能阅读完成。
umi 架构下:ts 我的项目中 redux 定义 module 每次都要写一遍类型定义麻烦得很
typing 文件夹下创立 Redux.d.ts 申明文件
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;
如何应用
models 文件夹下创立 staff.ts
type StaffSettingState = {staff: Record<string, never>;};
const StaffSettingsModel: MyRedux.Models<StaffSettingState> = {
namespace: 'staffSettingsModel',
state: {staff: {}
},
effects: {},
reducers: {},};
export default StaffSettingsModel;
正文完