javelin
javelin copied to clipboard
Cannot use 'in' operator to search for 'Symbol(javelin_field_kind)' in undefined
First, thanks for your work on javelin - I'm learning about ECS and found your TypeScript implementation very elegant!
I'm trying to adapt your client-server example from https://github.com/3mcd/javelin/tree/next/examples/spin to synchronize an entity with a simple component over a WebSocket. Using the latest version (1.0.0-alpha.15
) of net
there is an unclear error message on the client side:
model_helpers.ts:196 Uncaught TypeError: Cannot use 'in' operator to search for 'Symbol(javelin_field_kind)' in undefined
at isSchema (model_helpers.ts:196:12)
at getTarget (pack.ts:163:7)
at decodeInner (pack.ts:186:12)
at decode (pack.ts:279:10)
at decodeSnapshotPart (message_handler.ts:87:14)
at decode2 (message_handler.ts:189:11)
at Object.system (message_handler.ts:208:7)
at Object.executor (world.ts:42:15) # handler.system();
at effect (effect.ts:201:25) # useNet = createEffect(
at world.ts:52:23
Any advice? Please let me know if you need more context to replicate or understand the problem.
Update: The error seems to be related to using a string field in a component. Changing the field to a number removes the error.
import { registerSchema, string, number } from "@javelin/ecs";
export const Render = {
asset: number, # decoding fails when this is a string
};
registerSchema(Render, 3);
The same error occurs for empty components. Adding a dummy number field fixes it again.
@max-vogler Sorry I took so long to reply. Could you try to specify the length of the string you're trying to encode in the schema? That'd look something like this:
export const Render = {
asset: { ...string, length: 99 },
};
Apologies for the poor documentation. I'm working on new docs (and a new version of Javelin) in a separate repo that I hope to make public by the end of the year.