From fde34699ebc5f2cd668aa33577ee091373c4c9bb Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 15 Jun 2025 23:14:45 -0400 Subject: [PATCH] discriminatedUnion (#1193) ## Description: Use the `discriminatedUnion` zod function to more accurately describe how the `type` field is being used. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/core/Schemas.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index a25b823b2..d3f0256ae 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -372,7 +372,7 @@ export const ServerDesyncSchema = ServerBaseMessageSchema.extend({ yourHash: z.number().optional(), }); -export const ServerMessageSchema = z.union([ +export const ServerMessageSchema = z.discriminatedUnion("type", [ ServerTurnMessageSchema, ServerPrestartMessageSchema, ServerStartGameMessageSchema, @@ -428,7 +428,7 @@ export const ClientJoinMessageSchema = z.object({ flag: SafeString.optional(), }); -export const ClientMessageSchema = z.union([ +export const ClientMessageSchema = z.discriminatedUnion("type", [ ClientSendWinnerSchema, ClientPingMessageSchema, ClientIntentMessageSchema,