From a1ca6651194c64ba2c8ae45a8adfcafe90a5a985 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 30 May 2024 10:07:58 -0700 Subject: [PATCH] compose_ui: Fix TypeScript noUncheckedIndexedAccess errors. Signed-off-by: Anders Kaseorg --- web/src/compose_ui.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts index cf46fc6273..e8d42a6c5b 100644 --- a/web/src/compose_ui.ts +++ b/web/src/compose_ui.ts @@ -144,7 +144,7 @@ export function set_focus(opts: ComposeTriggeredOptions): void { } export function smart_insert_inline($textarea: JQuery, syntax: string): void { - function is_space(c: string): boolean { + function is_space(c: string | undefined): boolean { return c === " " || c === "\t" || c === "\n"; } @@ -333,7 +333,7 @@ export function compute_placeholder_text(opts: ComposePlaceholderOptions): strin }); const recipient_names = util.format_array_as_list(recipient_parts, "long", "conjunction"); - if (users.length === 1) { + if (users.length === 1 && users[0] !== undefined) { // If it's a single user, display status text if available const user = users[0]; const status = user_status.get_status_text(user.user_id); @@ -896,8 +896,9 @@ export function format_text( text.slice(range.start + 1, range.end - 1).includes("]("); if (is_selection_link()) { - const description = selected_text.split("](")[0].slice(1); - let url = selected_text.split("](")[1].slice(0, -1); + const i = selected_text.indexOf("](", 1); + const description = selected_text.slice(1, i); + let url = selected_text.slice(i + "](".length, -1); url = url_to_retain(url); text = text.slice(0, range.start) +