【发布时间】:2022-11-02 00:20:45
【问题描述】:
我遇到了将项目升级到 rxjs > 7 redux-observable@2 typescript@4.8.4
期望是 ofType 运算符缩小了可区分的联合,但它似乎没有工作。对我来说,它看起来应该。
enum ActionTypes {
TEST_ACTION = "TEST_ACTION",
TEST_ACTION2 = "TEST_ACTION2"
}
interface TTestAction extends Action<ActionTypes.TEST_ACTION> {
payload: string;
}
interface TTestAction2 extends Action<ActionTypes.TEST_ACTION2> {}
type TAppActions = TTestAction | TTestAction2;
export const testEpic = (action$: Observable<TAppActions>) =>
action$.pipe(
ofType(ActionTypes.TEST_ACTION),
tap((action) => {
// expecting action to be narrowed to TTestAction type with inferred type
// params ofType<TAppActions, ActionTypes.TEST_ACTION, TTestAction>
// and payload to be accessible but action is still typed as the union
}),
mapTo({ type: ActionTypes.TEST_ACTION2 })
);
/**
export function ofType<
// All possible actions your app can dispatch
Input extends Action,
// The types you want to filter for
Type extends Input['type'],
// The resulting actions that match the above types
Output extends Input = Extract<Input, Action<Type>>
>(...types: [Type, ...Type[]]): OperatorFunction<Input, Output>
*/
【问题讨论】:
-
在此处发布您的代码,不要让有兴趣帮助您点击某些外部站点的人。
-
感谢您的帮助@possum
标签: rxjs redux-observable