Fix filteredArray logic

develop^2
Alex Gleason 2023-03-13 16:37:40 -05:00
rodzic d0ceac9987
commit e9ae8d2c45
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -4,10 +4,13 @@ import type { CustomEmoji } from './custom-emoji';
/** Validates individual items in an array, dropping any that aren't valid. */
function filteredArray<T extends z.ZodTypeAny>(schema: T) {
return z.any().array().transform((arr) => (
arr.map((item) => schema.safeParse(item).success ? item as z.infer<T> : undefined)
.filter((item): item is z.infer<T> => 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<T> => Boolean(item))
));
}
/** Map a list of CustomEmoji to their shortcodes. */