From e71eaf6418988b7762c2e605673f95c69eeba0ff Mon Sep 17 00:00:00 2001 From: Jordan Fearnley Date: Thu, 13 Jun 2024 13:18:38 +0100 Subject: [PATCH] Misc: Resolve future TS version errors [no-ci] (#939) --- src/components/Utilities/UtilitiesTable.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/Utilities/UtilitiesTable.tsx b/src/components/Utilities/UtilitiesTable.tsx index af4c0fd7f..2f49843e1 100644 --- a/src/components/Utilities/UtilitiesTable.tsx +++ b/src/components/Utilities/UtilitiesTable.tsx @@ -135,7 +135,7 @@ const Row = ( ); }; -const isFileSortCriteriaEnum = (type: unknown): type is keyof typeof FileSortCriteriaEnum => typeof type === 'number'; +const isCriteriaMapKey = (type: string): type is keyof typeof criteriaMap => type in criteriaMap; const HeaderItem = ( props: { @@ -165,20 +165,17 @@ const HeaderItem = ( } const handleSortCriteriaChange = (headerId: string) => { - if (skipSort || !isFileSortCriteriaEnum(criteriaMap[headerId])) return; - const criteria = criteriaMap[headerId] as FileSortCriteriaEnum; + if (skipSort || !isCriteriaMapKey(headerId)) return; + const criteria = criteriaMap[headerId]; if (!criteria || !setSortCriteria) return; - setSortCriteria((tempCriteria) => { - if (tempCriteria === criteria) return tempCriteria * -1; - return criteria; - }); + setSortCriteria(prevCriteria => ((prevCriteria === criteria) ? -criteria : criteria)); }; const sortIndicator = (headerId: string) => { - if (skipSort || !isFileSortCriteriaEnum(criteriaMap[headerId])) return null; - const criteria = criteriaMap[headerId] as number; - if (!criteria || !sortCriteria || Math.abs(sortCriteria) !== criteria) return null; + if (skipSort || !isCriteriaMapKey(headerId)) return null; + const criteria = criteriaMap[headerId]; + if (!criteria || !sortCriteria || Math.abs(sortCriteria) !== criteria as number) return null; return (