- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在通过 NgRx Doumentation 的 createAction 方法,如下面的链接:
Overloads for createAction method
我无法理解下面这个方法的类型签名,特别是 createAction 方法的返回类型:
什么是
() => TypedAction<T>
ActionCreator<T, () => TypedAction<T>>
TypedAction
的任何引用?这是否意味着任何特定 Action 类型的形状对象?
TypedAction
的某个函数T 型。
最佳答案
TypedAction
是一个通用接口(interface),它通过添加只读 type
来扩展 Action 类型属性(property)。
export declare interface TypedAction<T extends string> extends Action {
readonly type: T;
}
ActionCreator<T, () => TypedAction<T>>
- 告诉我们我们有一个工厂,它返回一个 TypedAction 对象
() => ({ type: T})
export const logout = createAction('[Auth] Logout');
createAction
函数在 action_creator.ts 中定义。
export function createAction<T extends string>(
type: T
): ActionCreator<T, () => TypedAction<T>>;
createAction
将返回一个函数,该函数又返回一个带有
type
的对象在我们的例子中,字符串的属性为
<T extends string>
export function createAction<T extends string, C extends Creator>(
type: T,
config?: { _as: 'props' } | C
): Creator {
...
case 'empty':
return defineType(type, () => ({ type }));
...
}
function defineType(type: string, creator: Creator): Creator {
return Object.defineProperty(creator, 'type', {
value: type,
writable: false,
});
}
defineType
接受类型 ('[Auth] Logout') 和 Creator -
() => ({ type })
.它返回 Creator 但带有一个新属性
type
.
logout.type
和
logout().type
将返回相同的值 - '[Auth] Logout'
关于typescript - NgRx createAction 方法返回类型签名的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58690209/
我的struts应用程序有问题,用户被要求使用表单操作作为userUpdateAction更新他的详细信息,表单bean是UserUpdateForm。我有servlet过滤器来检查用户是否已经登录。
有两种创建 ngrx Action 的方法。一种是定义一个实现 Action 类的新类,另一种是使用“createAction”函数。有没有办法获取使用“createAction”方法创建的操作的类型
我一直在通过 NgRx Doumentation 的 createAction 方法,如下面的链接: Overloads for createAction method 我无法理解下面这个方法的类型签
我是 JTable 的新手,当我创建新条目时,表不会刷新,但当我更新或删除时,表不会刷新。在 Servlet 中,我为新创建的对象创建一个 arrayList(它已正确插入到数据库中),因此生成的 J
我正在尝试使用 extbase 创建一些东西,但我收到的错误消息不是很有帮助。我以 blog_example 扩展作为指南。一个(可能)重要的区别是:我没有数据库表,因为我想编写一个自定义域存储库,通
最近几天我一直在谷歌上疯狂地搜索(没有成功)如何覆盖 SonataAdmin 操作以捕获 session 用户名并将其保存在外键字段中。 附件管理 Controller 类: get('request
我有这样定义的 Action 类型: type Action = { type: 'DO_X' } | { type: 'DO_Y', payload: string }
我看到了这个 roboletirc 示例: @Test public void shouldHaveHappySmiles() throws Exception { String hel
我想创建一个 NgRx Action 创建工厂。但我不知道如何将泛型类型传递给 props方法。 import { createAction, props } from "@ngrx/store";
我想在 React + Redux 中构建一个函数,当用户单击一个按钮时,调用 API 并将数据加载到商店中,然后在页面上显示数据。 我想使用 redux-actions 框架:https://red
Redux 工具包提供 createAction辅助方法。我在引用使用 createAction 创建的操作时遇到问题作为类型。 例如 : const getData = createAction>(
我按照 YouTube 上的教程尝试创建自己的项目,但浏览器中不断出现错误,提示 Dispatch 需要一个对象。 我的模特: export interface Football { title:
我是一名优秀的程序员,十分优秀!