From e06167481c3698e4b0fd656b070e4368c136878f Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Tue, 9 Jan 2024 07:52:00 -0600 Subject: [PATCH] fix: zodded typescript --- src/data/data-types.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/data/data-types.ts b/src/data/data-types.ts index 8ae48b8..0a15165 100644 --- a/src/data/data-types.ts +++ b/src/data/data-types.ts @@ -35,20 +35,28 @@ const roomSchemaHelper = z .toUpperCase() .trim() .transform(normalizeRoomString) - .refine((val) => Object.hasOwn(rooms, val) || val === ""); + .refine((val) => Object.hasOwn(rooms, val)); /** * Represents the custom schema for a room. * * This schema is used to validate if a value is a valid room. * A valid room, well, exists in the list of rooms. - * In addition, this allows an empty string to pass, so that that validation can be caught better. */ -const roomSchema = z.custom( +const roomSchema = z.custom( (val) => roomSchemaHelper.safeParse(val).success, (val) => ({ message: `${val} is not a room` }), ); +/** + * Represents the custom schema for a room. + * + * This schema is used to validate if a value is a valid room. + * A valid room, well, exists in the list of rooms. + * In addition, this allows an empty string to pass, so that that validation can be caught better. + */ +const roomSchemaUnion = z.union([roomSchema, z.literal("")]); + /** * Represents the schema for profiles data. */ @@ -97,7 +105,7 @@ const stairListSchema = z.record( export { profilesListSchema, - roomSchema, + roomSchemaUnion as roomSchema, type Level, type Lvl, type ProfilesList,