Error - The type you provided for 'RoomEvent' is not a valid JSON value

Why this error occurred

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

For example, suppose you have defined three broadcastable events for your application:

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

How to fix it

You’ll need to figure out what part of your provided RoomEvent type definition isn’t valid JSON. Sometimes this is immediately obvious, but sometimes the issue may be a bit less obvious.

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:

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