angulartypescriptngrxngrx-effectsngrx-store-4.0

Upgrading ngrx 2 -> 4. Having issue with typing in de-structuring array


The error is saying that it's expecting a comma after the action parameter in the .map.

There's also an error when hovering over DataActions.AddDataAction which says Tuple type '[Action, AppStore]' with length '2' cannot be assigned to tuple with length '5'

@Effect() addData$ = this.actions$
    .ofType(DataActions.ADD_DATA)
    .withLatestFrom(this.store$)
    .map(([action: DataActions.AddDataAction, store: AppState]) => [action.payload, reducer.dataResults(store)])
    .etc...

Here's the relevant packages and their versions in my package.json

"@ngrx/effects": "^4.1.1",
"@ngrx/router-store": "^4.1.1",
"@ngrx/store": "^4.1.1",
"@ngrx/store-devtools": "^4.1.1",
"typescript": "~2.4.0",

Solution

  • withLastFrom() actually returns a Tuple type and to declare type of each element within a Tuple, we need to do something like

    map(([action, store]: [DataActions.AddDataAction, AppState])=>