# Schema

> The Schema interface of the Room API is a room's declared kinds and calls, which the room and its clients build from the same declarations.

The **`Schema`** interface of the [Room API](/docs/room) is a room's declared kinds and calls, as [`defineSchema()`](/docs/room/defineschema) returns them. The room passes it as `schema` to [`defineRoom()`](/docs/room/defineroom), and its clients pass the same one to `connect`.

## Instance properties

`Schema.hash`
: A number computed from the kinds, their fields and the input kind, which clients send when they connect. A client whose schema has another hash is refused with close code 4004. Read only.

`Schema.state`
: The shared state kind. Read only.

`Schema.private`
: The private state kind. Read only.

`Schema.entities`
: An array of the entity kinds. Read only.

`Schema.calls`
: The calls from [`defineCalls()`](/docs/room/definecalls). They aren't part of the hash. Read only.

`Schema.input`
: The input kind, or `undefined`. It's part of the hash when set. Read only.

## Description

`RoomOf<typeof schema>` is the type of the [`Room`](/docs/room/room) a room declared with the schema gets, for typing helpers, and `CallsOf<typeof schema>` the type of a client's `room.calls`.

## Examples

### Typing a helper from the schema

```ts
// rounds.ts
import { defineRoom, defineSchema, entity, type RoomOf } from "@irtio/room";

const Round = entity("round", { number: "u8", phase: "string" });
const schema = defineSchema({ state: Round });

function nextRound(room: RoomOf<typeof schema>) {
  room.state.number++;
  room.state.phase = "countdown";
}

export default defineRoom({
  schema,
  onMessage(room, _connection, message) {
    if (message === "next") nextRound(room);
  },
});
```

## See also

- [`defineSchema()`](/docs/room/defineschema)
- [State sync and interest](/docs/room/guides/state-sync)
