ffrostfall / ByteNet

An advanced, modern networking library for Luau/Roblox
https://ffrostfall.github.io/ByteNet/
MIT License
77 stars 16 forks source link

struct's inside of array's are not typed correctly (ts) #11

Closed strawbberrys closed 7 months ago

strawbberrys commented 7 months ago

For some reason, using a struct inside of an array causes the struct to need the value key when being declared.

ex:

export const reflex = defineNamespace("reflex", () => {
    const broadcastAction = struct({
        name: string,
        arguments: array(unknown),
    });

    return {
        dispatch: definePacket({
            value: array(broadcastAction),
            reliabilityType: "reliable",
        }),
    };
});

reflex.dispatch.sendToAll([{ name: "a", arguments: [] }]); // does not work
reflex.dispatch.sendToAll([{ value: { name: "a", arguments: [] } }]); // works
reflex.dispatch.sendToAll([{ name: "a", arguments: [] }]);
-----------------------------^^^^
Object literal may only specify known properties, and 'name' does not exist in type 'struct<{ name: ByteNetType<string>; arguments: array<ByteNetType<unknown>>; }>'.
strawbberrys commented 7 months ago

I've figured out the problem and created a pull request which fixes this issue. https://github.com/ffrostflame/ByteNet/pull/12