From e9ae8d2c453d3753730b983a980816816ebfb134 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 13 Mar 2023 16:37:40 -0500 Subject: [PATCH] Fix filteredArray logic --- app/soapbox/schemas/utils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/soapbox/schemas/utils.ts b/app/soapbox/schemas/utils.ts index d0bc4cc8f8..72f5f49d9b 100644 --- a/app/soapbox/schemas/utils.ts +++ b/app/soapbox/schemas/utils.ts @@ -4,10 +4,13 @@ import type { CustomEmoji } from './custom-emoji'; /** Validates individual items in an array, dropping any that aren't valid. */ function filteredArray(schema: T) { - return z.any().array().transform((arr) => ( - arr.map((item) => schema.safeParse(item).success ? item as z.infer : undefined) - .filter((item): item is z.infer => Boolean(item)) - )); + return z.any().array() + .transform((arr) => ( + arr.map((item) => { + const parsed = schema.safeParse(item); + return parsed.success ? parsed.data : undefined; + }).filter((item): item is z.infer => Boolean(item)) + )); } /** Map a list of CustomEmoji to their shortcodes. */