javelin icon indicating copy to clipboard operation
javelin copied to clipboard

Cannot use 'in' operator to search for 'Symbol(javelin_field_kind)' in undefined

Open max-vogler opened this issue 1 year ago • 3 comments

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.

max-vogler avatar Sep 09 '22 23:09 max-vogler

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);

max-vogler avatar Sep 10 '22 11:09 max-vogler

The same error occurs for empty components. Adding a dummy number field fixes it again.

max-vogler avatar Sep 11 '22 16:09 max-vogler

@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.

3mcd avatar Sep 18 '22 13:09 3mcd