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

Redux Toolkit · Type Alias

EntityId

EntityId is Redux Toolkit's type for an entity identifier. It is defined as number | string, covering numeric and textual IDs used by normalized entity state.

How it works

EntityId is a union type for identifiers used by Redux Toolkit's entity-state APIs. An identifier may be either a number or a string, so it can represent numeric database keys and textual keys alike.

Syntax

export type EntityId = number | string

Key points

  • EntityId accepts exactly two primitive forms: number and string.
  • Entity IDs identify individual items in an entity collection.
  • Entity records are represented as a mapping keyed by EntityId.
  • An IdSelector receives a model and returns its EntityId.

Common mistakes

  • Entity IDs cannot use arbitrary types such as objects, arrays, booleans, or symbols; use only strings or numbers.

Example: Using EntityId values

import type { EntityId } from '@reduxjs/toolkit'

const bookId: EntityId = 'book-1'
const otherId: EntityId = 42

console.log(bookId, otherId)

This TypeScript example assigns both supported EntityId forms: a string and a number.

When to use it

Type entity identifiers

Typing IDs returned by entity selectors or model-specific ID selectors.

Model normalized state

Representing normalized adapter state with IDs and keyed records.

Handle mixed ID formats

Supporting APIs whose identifiers are either numeric or textual.

Interview questions

QWhat is EntityId in Redux Toolkit?

EntityId is the shared identifier type used by Redux Toolkit's entity APIs. Its definition is the union number | string, allowing either numeric or textual IDs.

Follow-up: Why is a union preferable here? It preserves type checking while supporting common identifier formats without forcing every application to convert IDs.

QWhere does EntityId appear in normalized entity state?

An entity adapter stores IDs in its normalized ids collection, while entity records are keyed by those identifiers in entities. EntityId describes the allowed ID values for that normalized state.

Follow-up: What state shape uses these IDs? ids is an EntityId array, and entities maps EntityId keys to entity values.

QHow does EntityId relate to selectId and IdSelector?

IdSelector<T> returns an EntityId for a model, and an adapter's selectId callback identifies each entity. The default selector reads entity.id, but a custom selector is needed when the ID is stored elsewhere.

Follow-up: When should a custom selector be supplied? Use one whenever the entity's unique identifier is not in its id field.

  • createEntityAdapter
  • EntityState
  • IdSelector
  • Comparer
  • selectId

Source: createEntityAdapter. Checked 2026-10-15.