Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
eslint: Fix @typescript-eslint/prefer-optional-chain.
Anders Kaseorgcd1ced82d6d4
diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.tsindex 8c5b99e1699..2751e5e718c 100644--- a/web/src/click_handlers.ts+++ b/web/src/click_handlers.ts@@ -683,7 +683,7 @@ export function initialize(): void {const $elem = $(this);const user_ids_string = $elem.attr("data-user-ids-string");// Don't show tooltip for group direct messages.- if (!user_ids_string || user_ids_string.split(",").length !== 1) {+ if (user_ids_string?.split(",").length !== 1) {return;}const title_data = recent_view_ui.get_pm_tooltip_data(user_ids_string);diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.tsindex f37bcc6ce90..8b7168c530b 100644--- a/web/src/compose_paste.ts+++ b/web/src/compose_paste.ts@@ -127,7 +127,7 @@ export function is_white_space_pre(paste_html: string): boolean {function is_from_excel(html_fragment: HTMLBodyElement): boolean {const html_tag = html_fragment.parentElement;- if (!html_tag || html_tag.nodeName !== "HTML") {+ if (html_tag?.nodeName !== "HTML") {return false;}@@ -166,7 +166,7 @@ function is_from_excel(html_fragment: HTMLBodyElement): boolean {// something like LibreOffice Writer.function is_from_libreoffice_calc(body_tag: HTMLBodyElement): boolean {const html_tag = body_tag.parentElement;- if (!html_tag || html_tag.nodeName !== "HTML") {+ if (html_tag?.nodeName !== "HTML") {return false;}diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.tsindex 96cc06d1a86..b279acbb6cb 100644--- a/web/src/composebox_typeahead.ts+++ b/web/src/composebox_typeahead.ts@@ -1253,8 +1253,7 @@ export function content_typeahead_selected(const sub = stream_data.get_sub_by_name(item.name);const is_empty_topic_only_channel =sub && stream_data.is_empty_topic_only_channel(sub.stream_id);- const is_greater_than_key_pressed =- event && event.type === "keydown" && event.key === ">";+ const is_greater_than_key_pressed = event?.type === "keydown" && event.key === ">";// For empty topic only channel, skip showing topic typeahead and// insert direct channel link.diff --git a/web/src/hotkey.ts b/web/src/hotkey.tsindex 1f03cc0927f..9f7f28e2f86 100644--- a/web/src/hotkey.ts+++ b/web/src/hotkey.ts@@ -1199,7 +1199,7 @@ function process_hotkey(e: JQuery.KeyDownEvent, hotkey: Hotkey): boolean {case "toggle_topic_visibility_policy":if (recent_view_ui.is_in_focus()) {const recent_msg = recent_view_ui.get_focused_row_message();- if (recent_msg !== undefined && recent_msg.type === "stream") {+ if (recent_msg?.type === "stream") {user_topics_ui.toggle_topic_visibility_policy(recent_msg);return true;}@@ -1217,13 +1217,13 @@ function process_hotkey(e: JQuery.KeyDownEvent, hotkey: Hotkey): boolean {case "list_of_channel_topics":if (recent_view_ui.is_in_focus()) {const msg = recent_view_ui.get_focused_row_message();- if (msg !== undefined && msg.type === "stream") {+ if (msg?.type === "stream") {list_of_channel_topics_channel_id = msg.stream_id;}}if (inbox_ui.is_in_focus()) {const msg = inbox_ui.get_focused_row_message();- if (msg !== undefined && msg.msg_type === "stream") {+ if (msg?.msg_type === "stream") {list_of_channel_topics_channel_id = msg.stream_id;}}diff --git a/web/src/integration_url_modal.ts b/web/src/integration_url_modal.tsindex 3cacc2b334c..633b5013b49 100644--- a/web/src/integration_url_modal.ts+++ b/web/src/integration_url_modal.ts@@ -106,8 +106,7 @@ export function show_generate_integration_url_modal(api_key: string): void {if (!$("#integration-url-all-branches").prop("checked") &&- branch_pill_widget !== undefined &&- branch_pill_widget.items().length === 0+ branch_pill_widget?.items().length === 0) {branch_pill_widget.appendValue("main");}diff --git a/web/src/message_view.ts b/web/src/message_view.tsindex 1a322ca0996..164783632ab 100644--- a/web/src/message_view.ts+++ b/web/src/message_view.ts@@ -90,7 +90,7 @@ export function reset_ui_state(opts: {trigger?: string}): void {// Most users aren't going to send a bunch of a out-of-narrow messages// and expect to visit a list of narrows, so let's get these out of the way.let skip_automatic_new_visibility_policy_banner = false;- if (opts && opts.trigger === "outside_current_view") {+ if (opts?.trigger === "outside_current_view") {skip_automatic_new_visibility_policy_banner = true;}compose_banner.clear_message_sent_banners(true, skip_automatic_new_visibility_policy_banner);diff --git a/web/src/rendered_markdown.ts b/web/src/rendered_markdown.tsindex e0932f2f168..0932b0ce349 100644--- a/web/src/rendered_markdown.ts+++ b/web/src/rendered_markdown.ts@@ -322,7 +322,7 @@ export const update_elements = ($content: JQuery): void => {const $codehilite = $(this);const $pre = $codehilite.find("pre");const fenced_code_lang = $codehilite.attr("data-code-language");- let playground_info;+ let playground_info: realm_playground.RealmPlayground[] | undefined;if (fenced_code_lang !== undefined) {playground_info = realm_playground.get_playground_info_for_languages(fenced_code_lang);}@@ -339,11 +339,7 @@ export const update_elements = ($content: JQuery): void => {// popover listing the options.let title = $t({defaultMessage: "View in playground"});const $view_in_playground_button = $buttonContainer.find(".code_external_link");- if (- playground_info &&- playground_info.length === 1 &&- playground_info[0] !== undefined- ) {+ if (playground_info?.length === 1 && playground_info[0] !== undefined) {title = $t({defaultMessage: "View in {playground_name}"},{playground_name: playground_info[0].name},diff --git a/web/src/spoilers.ts b/web/src/spoilers.tsindex d7ed450c621..cd2ef154775 100644--- a/web/src/spoilers.ts+++ b/web/src/spoilers.ts@@ -66,7 +66,7 @@ export function initialize(): void {// Allow selecting text inside a spoiler header.const selection = document.getSelection();- if (selection && selection.type === "Range") {+ if (selection?.type === "Range") {return;}diff --git a/web/src/unread.ts b/web/src/unread.tsindex 41628561aba..723c9641fc9 100644--- a/web/src/unread.ts+++ b/web/src/unread.ts@@ -597,7 +597,7 @@ class UnreadTopicCounter {// topic in this stream containing a given unread message// ID. If it's not in this stream, we'll get undefined.const stream_topic = this.reverse_lookup.get(message_id);- if (stream_topic !== undefined && stream_topic.stream_id === stream_id) {+ if (stream_topic?.stream_id === stream_id) {// Important: We lower-case topics here before adding them// to this set, to support case-insensitive checks.result.add(stream_topic.topic.toLowerCase());