Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

refactor: Use variables to get TypeScript type narrowing.

Priyank Patel43da43701b1b
diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js
index 7e0909d017e..fe75deb3dd4 100644
--- a/frontend_tests/node_tests/common.js
+++ b/frontend_tests/node_tests/common.js
@@ -9,9 +9,9 @@ const $ = require("../zjsunit/zjquery");
const noop = () => {};
mock_esm("tippy.js", {
- default: (selector) => {
- $(selector)[0]._tippy = noop;
- $(selector)[0]._tippy.setContent = noop;
+ default: (arg) => {
+ arg._tippy = {setContent: noop};
+ return arg._tippy;
},
});
diff --git a/static/js/blueslip.js b/static/js/blueslip.js
index e2dc3808505..b3ef413309f 100644
--- a/static/js/blueslip.js
+++ b/static/js/blueslip.js
@@ -90,11 +90,12 @@ function report_error(
}
const key = ":" + msg + stack;
+ const last_report_time = last_report_attempt.get(key);
if (
reported_errors.has(key) ||
- (last_report_attempt.has(key) &&
+ (last_report_time !== undefined &&
// Only try to report a given error once every 5 minutes
- Date.now() - last_report_attempt.get(key) <= 60 * 5 * 1000)
+ Date.now() - last_report_time <= 60 * 5 * 1000)
) {
return;
}
diff --git a/static/js/common.js b/static/js/common.js
index 7c0173c73c0..2db42774b0f 100644
--- a/static/js/common.js
+++ b/static/js/common.js
@@ -71,8 +71,9 @@ export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {
}
for (const key of keys) {
- if (keys_map.get(key)) {
- key_text = key_text.replace(key, keys_map.get(key));
+ const replace_key = keys_map.get(key);
+ if (replace_key !== undefined) {
+ key_text = key_text.replace(key, replace_key);
}
}
@@ -85,10 +86,9 @@ export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {
function set_password_toggle_label(password_selector, label, tippy_tooltips) {
$(password_selector).attr("aria-label", label);
if (tippy_tooltips) {
- if (!$(password_selector)[0]._tippy) {
- tippy(password_selector);
- }
- $(password_selector)[0]._tippy.setContent(label);
+ const element = $(password_selector)[0];
+ const tippy_instance = element._tippy ?? tippy(element);
+ tippy_instance.setContent(label);
} else {
$(password_selector).attr("title", label);
}