Fix filteredArray logic
This commit is contained in:
parent
d0ceac9987
commit
e9ae8d2c45
1 changed files with 7 additions and 4 deletions
|
@ -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. */
|
||||
|
|
Loading…
Reference in a new issue