Skip to content

Commit

Permalink
fix: Better type narrowing in calculationSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Aug 2, 2024
1 parent 05f038c commit 8148158
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/schemas/calculationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const calculationSchema = z.object({
.min(1, "housePostcode is required")
.refine(fixPostcode, "Invalid postcode")
.transform(parsePostcode)
.refine((postcode) => postcode.valid, { message: "Invalid postcode" }),
.refine(
(postcode): postcode is Extract<ReturnType<typeof parsePostcode>, { valid: true }> =>
postcode.valid,
),
houseSize: z.coerce.number().positive("houseSize must be a positive integer"),
houseAge: z.coerce.number().positive("houseAge must be a positive integer"),
houseBedrooms: z.coerce
Expand Down

0 comments on commit 8148158

Please sign in to comment.