---
meta:
  title: "The type you provided for 'Presence' is not a valid JSON object"
  parentTitle: "Error"
  description: "Your 'Presence' type is incorrect and needs to be updated"
---

## Why this error occurred

You have provided a custom `Presence` type for your application, but the type
you provided isn’t a (completely) valid JSON object. Values like `Date`, `Map`,
`Set`, functions, classes, or `unknown` aren’t valid JSON.

```ts highlight="4-7"
declare global {
  interface Liveblocks {
    Presence: {
      // Your own fields go here...
      cursor: { x: number; y: number } | null;
      selection: string[];
      lastActivity: Date; // ❌ The issue is here
    };
  }
}
```

In the example above, the problem is in the `Date` field, because a `Date` isn’t
a valid JSON value.

## How to fix it

You’ll need to figure out what part of your provided `Presence` type definition
isn’t valid JSON. Sometimes this is immediately obvious, like in the example
above.

Sometimes the issue may be a bit less obvious:

```ts highlight="6-7"
import type { Json } from "@liveblocks/client";

declare global {
  interface Liveblocks {
    Presence: {
      cursor: unknown; // ❌ Unknowns could contain non-JSON
      cursor: Json; // ✅ Prefer using Json
    };
  }
}
```

By using `Json`, you can still work with unknown or unspecified values, but
still ensure they will be valid JSON.

## If you cannot find the root cause

Sometimes types can be complex and the root cause is still unclear. In those
cases, there is a small trick you can use. Try to assign your type to the
required base type, with this line:

```ts highlight="9-10"
import type { JsonObject } from "@liveblocks/client";

declare global {
  interface Liveblocks {
    Presence: MyPresence;
  }
}

// Quick debugging snippet to find root cause
const xxx: JsonObject = {} as MyPresence;
//    ^?
//    The error will appear here
```

Now TypeScript will explain why it thinks your type isn’t valid JSON:

```error showLineNumbers={false}
Type 'MyPresence' is not assignable to type 'JsonObject'.
 Property 'lastActivity' is incompatible with index signature.
   Type 'Date' is not assignable to type 'Json | undefined'.
     Type 'Date' is not assignable to type 'JsonObject'.
       Index signature for type 'string' is missing in type 'Date'.
```

---

For an overview of all available documentation, see [/llms.txt](/llms.txt).
