reactjs - TS:没有类型的 Redux Actions
问题描述
我最近开始在我的 react 项目中使用 Typescript。我缺少的一件是键入调度和动作创建者。
我正在使用我自己的操作类型,基于:https ://redux.js.org/recipes/reducing-boilerplate
我的动作编码如下:
export function getXXX(){
return {
types: [
ActionTypes.GET_XXX,
ActionTypes.GET_XXX_SUCCESS,
ActionTypes.GET_XXX_ERROR
],
request: {
method: 'GET',
url: `/v1/retrievexxx`
}
}
}
我的问题是缺少类型(显然)并且 ReduxAction TS 类型需要一个类型。
有什么办法可以解决这个问题?
解决方案
I would really recommend not trying to work around this, and always provide a type
for your actions. There is a reason why the Action
type in the Redux typings requires it: big parts of the Redux ecosystem - such as the Dev Tools - expect it to be there, and will act weirdly if it's not. So it's probably not worth going against the grain here.
推荐阅读
- vim - 在vimscript中创建一个函数返回数组
- node.js - 如何修复 Aws-lambda 函数中的 nodejs 版本问题
- javascript - 如何在Javascript中将ASCII字符转换为可读值
- vuejs2 - 如果 vuejs 中的 url 错误,重定向到特定的 url
- .net - 在 VB.NET UWP 中发现和配对蓝牙设备
- python-3.x - 随机采样向量 ARMA 模型
- sql - 在 Spark-SQL 中为 Azure Databricks 创建用户定义(非临时)函数
- ios - 使用 swift 4 从 ios 监听 Firestore 中的实时更新
- android - UPI 隐式意图选择器在红米设备上不起作用
- spring-boot - Spring Boot,获取用于将数据库提取映射到 POJO 的查询