Error - The type you provided for 'UserMeta' does not match its requirements

Why this error occurred

You have provided a custom UserMeta type for your application, but the type you provided isn’t a (completely) valid definition.

In the example above, the problem is in the Date field. Values like Date, Map, Set, functions, classes, or unknown aren’t valid JSON.

The rules of the UserMeta type

The following rules apply if you want to specify a custom UserMeta type:

  • Top-level fields id and info are special. They are optional, but only these two fields can exist. Extra fields you specify will not have any effect and will be ignored.
  • If you specify id, it must still be assignable to string | undefined.
  • If you specify info, then it must be a valid JSON object value. Furthermore:
    • If you specify a name field inside info, it must still be assignable to string | undefined.
    • If you specify a avatar field inside info, it must still be assignable to string | undefined.

The reason for the last two restrictions is that some of our higher-level components will pick these values up and use them to provide default UIs.

Also please note:

How to fix it

You’ll need to figure out what part of your provided UserMeta type definition isn’t valid. 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: