From 2384f6c40ec26724199a9e9f05efa6ed02296bbc Mon Sep 17 00:00:00 2001 From: Beebles <102569435+beebls@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:46:49 -0600 Subject: [PATCH] ensure nulls arent passed to sort --- frontend/src/components/AnnouncementsDisplay.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/AnnouncementsDisplay.tsx b/frontend/src/components/AnnouncementsDisplay.tsx index 4ba813de..c6e6db1e 100644 --- a/frontend/src/components/AnnouncementsDisplay.tsx +++ b/frontend/src/components/AnnouncementsDisplay.tsx @@ -38,11 +38,16 @@ export function AnnouncementsDisplay() { setAnnouncements((oldAnnouncements) => { const newArr = [...oldAnnouncements, ...newAnnouncements]; const setOfIds = new Set(newArr.map((a) => a.id)); - return Array.from(setOfIds) - .map((id) => newArr.find((a) => a.id === id)!) - .sort((a, b) => { + return ( + ( + Array.from(setOfIds) + .map((id) => newArr.find((a) => a.id === id)) + // Typescript doesn't type filter(Boolean) correctly, so I have to assert this + .filter(Boolean) as Announcement[] + ).sort((a, b) => { return new Date(b.created).getTime() - new Date(a.created).getTime(); - }); + }) + ); }); }