From f5adc38c6680c98be18b7d9c1605f8c67edc1322 Mon Sep 17 00:00:00 2001 From: jq1836 <95712150+jq1836@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:24:19 +0800 Subject: [PATCH] Remove any type in checkKeyAndGetValue --- frontend/src/utils/repo-sorter.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/utils/repo-sorter.ts b/frontend/src/utils/repo-sorter.ts index 3a4b9b91cf..39c85b359d 100644 --- a/frontend/src/utils/repo-sorter.ts +++ b/frontend/src/utils/repo-sorter.ts @@ -10,13 +10,17 @@ function getGroupCommitsVariance(total: number, group: User) { return total + group.variance; } -function checkKeyAndGetValue(element: any, key: string | undefined) { - if (key === undefined || element === undefined || !(key in element)) { +function checkKeyAndGetValue(element: object, key: string | undefined) { + if (key === undefined || !(key in element)) { return undefined; } - return element[key]; + /** Casting here is safe as guard clause above ensures that element has an attribute with the same name as the string + * represented by key. */ + return (element as any)[key]; } +/** Array is not sorted when sortingOption is not provided. sortingOption is optional to allow it to fit the + * SortingFunction interface. */ function sortingHelper(element: User[], sortingOption?: string): string | number { if (sortingOption === 'totalCommits') { return element.reduce(getTotalCommits, 0);