Skip to main content
A state definition joins two things:
  • A schema that describes serializable saved data.
  • A class that gives your rules convenient methods.
The model and class must have matching fields. TypeScript reports a mismatch at .stateClass(GameState).

Available field schemas

Use t.object for data that needs no methods. Use t.state when nested data benefits from its own class.

Nest state classes

Define the child before its parent:
Commands receive hydrated GameState and PlayerState instances, so methods such as getPlayer are available while rules execute.

Initialize fields

Class field values become the defaults for a new game. Use .setup() on the game definition for values that depend on players, setup input, or randomness.
State must stay serializable. Do not store functions, class constructors, promises, dates, maps, or external service objects in fields.
Use ordinary class methods for calculations and repeated rule operations. Only fields listed in .model() are persisted.

Protect secret fields

Return a different state view to each player.