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.

web: Remove unchecked casts of jQuery .val().

Anders Kaseorg1da729e49fad
diff --git a/web/src/billing/billing.ts b/web/src/billing/billing.ts
index 29816282c21..6bda7f928af 100644
--- a/web/src/billing/billing.ts
+++ b/web/src/billing/billing.ts
@@ -38,7 +38,10 @@ export function initialize(): void {
}
e.preventDefault();
const current_licenses: number = $("#licensechange-input-section").data("licenses");
- const new_licenses: number = Number.parseInt($("#new_licenses_input").val() as string, 10);
+ const new_licenses: number = Number.parseInt(
+ $<HTMLInputElement>("input#new_licenses_input").val()!,
+ 10,
+ );
if (new_licenses > current_licenses) {
$("#new_license_count_holder").text(new_licenses);
$("#current_license_count_holder").text(current_licenses);
diff --git a/web/src/billing/upgrade.ts b/web/src/billing/upgrade.ts
index 8e7ab79700e..1419d2ef798 100644
--- a/web/src/billing/upgrade.ts
+++ b/web/src/billing/upgrade.ts
@@ -8,9 +8,9 @@ export const initialize = (): void => {
helpers.set_tab("upgrade");
helpers.set_sponsorship_form();
$("#add-card-button").on("click", (e) => {
- const license_management: string = $(
+ const license_management = $<HTMLInputElement>(
"input[type=radio][name=license_management]:checked",
- ).val() as string;
+ ).val()!;
if (!helpers.is_valid_input($(`#${CSS.escape(license_management)}_license_count`))) {
return;
}
@@ -37,18 +37,16 @@ export const initialize = (): void => {
monthly: page_params.monthly_price * (1 - page_params.percent_off / 100),
};
- $("input[type=radio][name=license_management]").on("change", function (this: HTMLInputElement) {
+ $<HTMLInputElement>("input[type=radio][name=license_management]").on("change", function () {
helpers.show_license_section(this.value);
});
- $("input[type=radio][name=schedule]").on("change", function (this: HTMLInputElement) {
+ $<HTMLInputElement>("input[type=radio][name=schedule]").on("change", function () {
helpers.update_charged_amount(prices, helpers.schedule_schema.parse(this.value));
});
- $("select[name=organization-type]").on("change", (e) => {
- const string_value = $((e.currentTarget as HTMLSelectElement).selectedOptions).attr(
- "data-string-value",
- );
+ $<HTMLSelectElement>("select[name=organization-type]").on("change", (e) => {
+ const string_value = $(e.currentTarget.selectedOptions).attr("data-string-value");
helpers.update_discount_details(helpers.organization_type_schema.parse(string_value));
});
@@ -59,11 +57,13 @@ export const initialize = (): void => {
$("#invoice_annual_price_per_month").text(helpers.format_money(prices.annual / 12));
helpers.show_license_section(
- $("input[type=radio][name=license_management]:checked").val() as string,
+ $<HTMLInputElement>("input[type=radio][name=license_management]:checked").val()!,
);
helpers.update_charged_amount(
prices,
- helpers.schedule_schema.parse($("input[type=radio][name=schedule]:checked").val()),
+ helpers.schedule_schema.parse(
+ $<HTMLInputElement>("input[type=radio][name=schedule]:checked").val(),
+ ),
);
};
diff --git a/web/src/portico/signup.ts b/web/src/portico/signup.ts
index 5c22e119b6e..3675a0c1afb 100644
--- a/web/src/portico/signup.ts
+++ b/web/src/portico/signup.ts
@@ -11,21 +11,21 @@ $(() => {
// NB: this file is included on multiple pages. In each context,
// some of the jQuery selectors below will return empty lists.
- const $password_field = $("#id_password, #id_new_password1");
+ const $password_field = $<HTMLInputElement>("input#id_password, input#id_new_password1");
if ($password_field.length > 0) {
$.validator.addMethod(
"password_strength",
(value: string) => password_quality(value, undefined, $password_field),
- () => password_warning($password_field.val() as string, $password_field),
+ () => password_warning($password_field.val()!, $password_field),
);
// Reset the state of the password strength bar if the page
// was just reloaded due to a validation failure on the backend.
- password_quality($password_field.val() as string, $("#pw_strength .bar"), $password_field);
+ password_quality($password_field.val()!, $("#pw_strength .bar"), $password_field);
$password_field.on("input", function () {
// Update the password strength bar even if we aren't validating
// the field yet.
- password_quality($(this).val() as string, $("#pw_strength .bar"), $(this));
+ password_quality($(this).val()!, $("#pw_strength .bar"), $(this));
});
}
@@ -143,13 +143,13 @@ $(() => {
},
});
- $(".register-page #email, .login-page-container #id_username").on(
+ $<HTMLInputElement>(".register-page input#email, .login-page-container input#id_username").on(
"focusout keydown",
function (e) {
// check if it is the "focusout" or if it is a keydown, then check if
// the keycode was the one for "Enter".
if (e.type === "focusout" || e.key === "Enter") {
- $(this).val(($(this).val() as string).trim());
+ $(this).val($(this).val()!.trim());
}
},
);
@@ -239,7 +239,9 @@ $(() => {
$("#change-email-address-visibility-modal .dialog_submit_button").on("click", () => {
const selected_val = Number.parseInt(
- $("#new_user_email_address_visibility").val() as string,
+ $<HTMLSelectElement & {type: "select-one"}>(
+ "select:not([multiple])#new_user_email_address_visibility",
+ ).val()!,
10,
);
$("#email_address_visibility").val(selected_val);
diff --git a/web/tests/billing.test.js b/web/tests/billing.test.js
index 60e7ea497cf..e447cf95e49 100644
--- a/web/tests/billing.test.js
+++ b/web/tests/billing.test.js
@@ -120,7 +120,7 @@ run_test("licensechange", ({override}) => {
assert.equal(key, "licenses");
return 20;
};
- $("#new_licenses_input").val = () => 15;
+ $("input#new_licenses_input").val = () => 15;
create_ajax_request_called = false;
const update_licenses_button_click_handler =
$("#update-licenses-button").get_on_handler("click");
@@ -128,7 +128,7 @@ run_test("licensechange", ({override}) => {
assert.ok(create_ajax_request_called);
assert.ok(!confirm_license_modal_shown);
- $("#new_licenses_input").val = () => 25;
+ $("input#new_licenses_input").val = () => 25;
create_ajax_request_called = false;
update_licenses_button_click_handler({preventDefault() {}});
assert.ok(!create_ajax_request_called);