Skip to content

Commit d9ce0d4

Browse files
committed
Punt on predicate type inference for now
1 parent 7f2b839 commit d9ce0d4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/action-listener-middleware/src/tests/listenerMiddleware.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,15 @@ describe('createActionListenerMiddleware', () => {
806806
})
807807

808808
middleware.addListener({
809-
predicate: (action, currentState): action is PayloadAction<number> => {
810-
return typeof action.payload === 'number'
809+
predicate: (
810+
action,
811+
currentState,
812+
previousState
813+
): action is PayloadAction<number> => {
814+
return typeof action.payload === 'boolean'
811815
},
812816
listener: (action, listenerApi) => {
817+
// @ts-expect-error
813818
expectExactType<PayloadAction<number>>(action)
814819
},
815820
})
@@ -878,12 +883,18 @@ describe('createActionListenerMiddleware', () => {
878883

879884
// Can pass a predicate function with fewer args
880885
typedMiddleware.addListener({
881-
predicate: (action, currentState): action is AnyAction => {
886+
// TODO Why won't this infer the listener's `action` with implicit argument types?
887+
predicate: (
888+
action: AnyAction,
889+
currentState: CounterState
890+
): action is PayloadAction<number> => {
882891
expectNotAny(currentState)
883892
expectExactType<CounterState>(currentState)
884893
return true
885894
},
886895
listener: (action, listenerApi) => {
896+
expectType<PayloadAction<number>>(action)
897+
887898
const listenerState = listenerApi.getState()
888899
expectExactType<CounterState>(listenerState)
889900
listenerApi.dispatch((dispatch, getState) => {

0 commit comments

Comments
 (0)