-
Hi, I have a specifc type for my chess game that I need to convert from a normal useState() to a liveblocks storage state. The type I need to store is this: type Piece = {
id: keyof typeof pieceIds;
};
type Board = (Piece | undefined)[][];
// ^ This I need!!! When I try to use it, I am doing something like this: As you can see, when I use it with I thought that undefined was JSON serializable. What's going on? Do I really need to convert my type to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Unfortunately, JavaScript does not allow Hope that helps to explain it. |
Beta Was this translation helpful? Give feedback.
Unfortunately, JavaScript does not allow
undefined
values to be serialized in JSON arrays. An array like[undefined]
would become[null]
on the other end, due to the fact thatJSON.parse(JSON.stringify([undefined])
returns[null]
. This is unfortunately out of our control. We therefore decided to not allowundefined
values as list members, because this implicit conversion could take people by surprise.Hope that helps to explain it.