nx: concatLatestFrom doesnt work with navigate when selecting more than one selector
Current Behavior
When passing 2 selectors as an array to concatLatestFrom there is a type mismatch error
Expected Behavior
Expected this to work as in NgRx repository this works and there is even a test for it to verify it works see https://github.com/ngrx/platform/blob/0bb49409413b784b1cc55c2b59e67ed760041aa5/modules/effects/spec/concat_latest_from.spec.ts#L87
Steps to Reproduce
I have an open issue on stackoverflow with a code example found here https://stackoverflow.com/q/68894745/6603342 But the ghist of it is
loadAllCases$ = createEffect(() => this._actions$.pipe(
concatLatestFrom(() => [
this.store.pipe(select(CaseSelectors.getAllCases)),
this.store.pipe(select(CaseSelectors.getCasesLoaded))
]),
navigation(this.caseLandingPage, {
run: (snap, [loaded, cases]) => {
if (loaded) {
return CaseActions.loadAllSuccess();
} else {
return this._caseService.getAll().pipe(
map(cases => CaseActions.loadAllSuccess(cases))
);
}
},
onError: (action, error) => {
return CaseActions.loadAllFailed(error);
}
})
));
This will work fine if i use one selector or create a selector dedicated for combining the state i wish to extract, but not when passed as an array. Note that this will also work just fine if i swap navigate for map, switchmap etc. or zip my two selectors.
Failure Logs
The error this produces is
TS2345: Argument of type 'OperatorFunction<Action, [Action, Calendar[], boolean]>' is not assignable to parameter of type 'OperatorFunction<Action, ActionOrActionWithState<unknown, Action>>'. Type '[Action, Calendar[], boolean]' is not assignable to type 'ActionOrActionWithState<unknown, Action>'. Type '[Action, Calendar[], boolean]' is not assignable to type '[Action, unknown]'. Source has 3 element(s) but target allows only 2.
Environment
"rxjs": "~6.6.0",
"@ngrx/effects": "~12.2.0",
"@ngrx/entity": "~12.2.0",
"@ngrx/router-store": "~12.2.0",
"@ngrx/store": "~12.2.0",
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (4 by maintainers)
Commits related to this issue
- feat(angular): support multiple state slices in data persistence ops A breaking change that enables data persistence operators to be used in streams with more than one slice of data (e.g., with `with... — committed to david-shortman/nx by david-shortman 3 years ago
- feat(angular): support multiple state slices in data persistence ops (#8216) A breaking change that enables data persistence operators to be used in streams with more than one slice of data (e.g., wi... — committed to nrwl/nx by david-shortman 2 years ago
I was able to reproduce locally. Will open a PR eventually.
The above example would work fine if i would swap navigation for NgRx
maporswitchMapetc… the issue comes when using Nx data persistent type such asnavigation. This will cause the application to fail to compile (if there is more than one selector) due to type incompatibility.