From 646128db9e9dd2e4063178d545983756381d8295 Mon Sep 17 00:00:00 2001 From: Aryan Bhokare <92683836+aryan-bhokare@users.noreply.github.com> Date: Wed, 1 Nov 2023 23:49:30 +0530 Subject: [PATCH] =?UTF-8?q?ts:=20Migrate=20=E2=80=98user=5Fsort.js?= =?UTF-8?q?=E2=80=99=20to=20TypeScript.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixes a bug in the people.ts User; `delivery_email` is never undefined. --- tools/test-js-with-node | 2 +- web/src/people.ts | 2 +- web/src/{user_sort.js => user_sort.ts} | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) rename web/src/{user_sort.js => user_sort.ts} (72%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index fa60007c2b..e1560e5aba 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -269,7 +269,7 @@ EXEMPT_FILES = make_set( "web/src/user_groups.ts", "web/src/user_profile.js", "web/src/user_settings.ts", - "web/src/user_sort.js", + "web/src/user_sort.ts", "web/src/user_status.ts", "web/src/user_status_ui.js", "web/src/user_topic_popover.js", diff --git a/web/src/people.ts b/web/src/people.ts index 78eab8a4cd..db6570f112 100644 --- a/web/src/people.ts +++ b/web/src/people.ts @@ -23,7 +23,7 @@ export type ProfileData = { export type User = { user_id: number; - delivery_email?: string | null; + delivery_email: string | null; email: string; full_name: string; date_joined: string; diff --git a/web/src/user_sort.js b/web/src/user_sort.ts similarity index 72% rename from web/src/user_sort.js rename to web/src/user_sort.ts index fc7db661ff..750b62ddb6 100644 --- a/web/src/user_sort.js +++ b/web/src/user_sort.ts @@ -1,4 +1,6 @@ -export function compare_a_b(a, b) { +import type {User} from "./people"; + +export function compare_a_b(a: number | string, b: number | string): number { if (a > b) { return 1; } else if (a === b) { @@ -7,7 +9,7 @@ export function compare_a_b(a, b) { return -1; } -export function sort_email(a, b) { +export function sort_email(a: User, b: User): number { const email_a = a.delivery_email; const email_b = b.delivery_email; @@ -27,10 +29,10 @@ export function sort_email(a, b) { return compare_a_b(email_a.toLowerCase(), email_b.toLowerCase()); } -export function sort_role(a, b) { +export function sort_role(a: User, b: User): number { return compare_a_b(a.role, b.role); } -export function sort_user_id(a, b) { +export function sort_user_id(a: User, b: User): number { return compare_a_b(a.user_id, b.user_id); }