Closed hzyhbk closed 2 years ago
当前在 effects 中 使用 dispatch 和 rootState 时并没有完整的类型提示, 有一种方式是通过as unknown as xx 的形式来断言,但这样在每次使用的时候都需要写一遍断言,体验相当不好。
dispatch
rootState
as unknown as xx
在 @ice/store 先声明两个 interface RootState 和 RootDisaptch
RootState
RootDisaptch
然后在实际项目中通过declare module '@ice/store' 的方式来扩大这两个类型
declare module '@ice/store'
这样操作之后就可以得到完整的类型提示了
但是这种方式的缺点就是需要自己把每个 model 都写一遍。尝试着用 models 的方式写,会报【以递归方式将自身引用为基类】的错误
当然每个 model 都写一遍声明,这种没啥意义的重复劳动可以在 ice 或者 rax 的 store 插件中通过工程化的方式来自动生成,做到用户无感。
找到了一种对源码修改更少的方式:
IcestoreModels
IcestoreRootState
IcestoreDispatch
效果如下:
Problem Description
当前在 effects 中 使用
dispatch
和rootState
时并没有完整的类型提示, 有一种方式是通过as unknown as xx
的形式来断言,但这样在每次使用的时候都需要写一遍断言,体验相当不好。Proposed Solution
在 @ice/store 先声明两个 interface
RootState
和RootDisaptch
然后在实际项目中通过
declare module '@ice/store'
的方式来扩大这两个类型这样操作之后就可以得到完整的类型提示了
但是这种方式的缺点就是需要自己把每个 model 都写一遍。尝试着用 models 的方式写,会报【以递归方式将自身引用为基类】的错误
当然每个 model 都写一遍声明,这种没啥意义的重复劳动可以在 ice 或者 rax 的 store 插件中通过工程化的方式来自动生成,做到用户无感。