diff --git a/packages/toolkit/src/matchers.ts b/packages/toolkit/src/matchers.ts index fca137e87..e8ca65107 100644 --- a/packages/toolkit/src/matchers.ts +++ b/packages/toolkit/src/matchers.ts @@ -12,14 +12,12 @@ import type { } from './createAsyncThunk' /** @public */ -export type ActionMatchingAnyOf< - Matchers extends [Matcher, ...Matcher[]] -> = ActionFromMatcher +export type ActionMatchingAnyOf[]]> = + ActionFromMatcher /** @public */ -export type ActionMatchingAllOf< - Matchers extends [Matcher, ...Matcher[]] -> = UnionToIntersection> +export type ActionMatchingAllOf[]]> = + UnionToIntersection> const matches = (matcher: Matcher, action: any) => { if (hasMatchFunction(matcher)) { @@ -38,7 +36,7 @@ const matches = (matcher: Matcher, action: any) => { * * @public */ -export function isAnyOf, ...Matcher[]]>( +export function isAnyOf[]]>( ...matchers: Matchers ) { return (action: any): action is ActionMatchingAnyOf => { @@ -55,7 +53,7 @@ export function isAnyOf, ...Matcher[]]>( * * @public */ -export function isAllOf, ...Matcher[]]>( +export function isAllOf[]]>( ...matchers: Matchers ) { return (action: any): action is ActionMatchingAllOf => { diff --git a/packages/toolkit/src/tests/matchers.typetest.ts b/packages/toolkit/src/tests/matchers.typetest.ts index e2b6ee8bf..8770983f0 100644 --- a/packages/toolkit/src/tests/matchers.typetest.ts +++ b/packages/toolkit/src/tests/matchers.typetest.ts @@ -312,3 +312,20 @@ function isRejectedWithValueTest(action: AnyAction) { expectExactType(action.error) } } + +function matchersAcceptSpreadArguments() { + const thunk1 = createAsyncThunk('a', () => 'a') + const thunk2 = createAsyncThunk('b', () => 'b') + const interestingThunks = [thunk1, thunk2] + const interestingPendingThunks = interestingThunks.map( + (thunk) => thunk.pending + ) + const interestingFulfilledThunks = interestingThunks.map( + (thunk) => thunk.fulfilled + ) + + const isLoading = isAnyOf(...interestingPendingThunks) + const isNotLoading = isAnyOf(...interestingFulfilledThunks) + + const isAllLoading = isAllOf(...interestingPendingThunks) +}