Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redux Toolkit · Function

isAnyOf

isAnyOf creates a type-safe matcher that succeeds when any supplied action creator or matcher function matches an action. It is commonly passed to builder.addMatcher or used in custom middleware.

How it works

Call isAnyOf with action creators or matcher functions to obtain a type guard. The returned guard evaluates to true when at least one supplied condition matches the tested action, making it useful with builder.addMatcher and custom middleware.

Syntax

isAnyOf(...matchers)

Parameters

NameTypeDescription
matchersActionCreator | TypeGuard ...One or more action creators or matcher functions accepted by the same input rules as isAllOf.

Returns

A type guard function that returns true when at least one supplied condition matches the tested action.

Key points

  • isAnyOf is part of Redux Toolkit's type-safe utilities for recognizing action patterns.
  • Use the returned matcher especially in builder.addMatcher cases.
  • The same matcher approach can be applied in custom middleware.
  • The function returned by isAnyOf is a TypeScript type guard, not just a plain boolean callback.
  • A tested action passes when at least one supplied condition matches.

Common mistakes

  • Its inputs follow the same rules as isAllOf; provide the supported action creators or matcher functions rather than arbitrary values.

Example: Match one of several action creators

import { isAnyOf, createAction } from '@reduxjs/toolkit'

const added = createAction<{ id: string }>('items/added')
const removed = createAction<{ id: string }>('items/removed')
const isItemChanged = isAnyOf(added, removed)

const action = removed({ id: 'a1' })
if (isItemChanged(action)) {
  console.log(action.payload.id)
}

Creates a matcher that accepts either of two action creators and narrows the action type inside the conditional.

When to use it

Group reducer matches

A reducer needs one case for several related actions.

Filter middleware actions

Middleware should react to any action in a selected set.

Narrow matched actions

TypeScript code needs safe narrowing after a match.

Interview questions

QWhat does isAnyOf do?

isAnyOf creates a type guard from multiple conditions. The guard returns true when at least one supplied condition matches the action.

Follow-up: How would you use it in a reducer? Pass the returned guard to builder.addMatcher so the reducer handles any matching action in one case.

QWhy use isAnyOf instead of checking action.type?

It is useful when matching several action types without manually comparing action.type values. The resulting predicate also provides TypeScript narrowing for the matched action.

Follow-up: Why prefer a matcher predicate over a string comparison? The predicate can combine multiple conditions and preserve type-safe narrowing.

QHow is isAnyOf called and evaluated?

Call isAnyOf with the desired action creators or matcher functions, then invoke the returned function with an action. It returns a boolean type-guard result.

Follow-up: What happens if no condition matches? The guard returns false, so the matcher case is skipped.

  • isAllOf
  • isAnyOf
  • isFulfilled
  • isPending
  • isRejected
  • builder.addMatcher
  • createReducer
  • createSlice

Source: Matching Utilities. Checked 2026-10-15.