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.

custom_profile_fields_ui: Avoid needless unchecked type assertion.

Anders Kaseorge13fecaf8ee6
diff --git a/tsconfig.json b/tsconfig.json
index b38ba375d54..e67a3528874 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -19,7 +19,7 @@
"*": ["./web/src/types/*"],
},
"resolveJsonModule": true,
- "types": ["@types/jquery.validation"],
+ "types": ["@types/jquery.validation", "flatpickr/dist/types/globals"],
/* Emit */
"noEmit": true,
diff --git a/web/src/custom_profile_fields_ui.ts b/web/src/custom_profile_fields_ui.ts
index a49ffe2fa20..57f5141228d 100644
--- a/web/src/custom_profile_fields_ui.ts
+++ b/web/src/custom_profile_fields_ui.ts
@@ -1,5 +1,6 @@
import flatpickr from "flatpickr";
import $ from "jquery";
+import assert from "minimalistic-assert";
import * as z from "zod/mini";
import render_settings_custom_user_profile_field from "../templates/settings/custom_user_profile_field.hbs";
@@ -18,6 +19,7 @@ import * as typeahead_helper from "./typeahead_helper.ts";
import * as ui_report from "./ui_report.ts";
import type {UserPillWidget} from "./user_pill.ts";
import * as user_pill from "./user_pill.ts";
+import {the} from "./util.ts";
const user_value_schema = z.array(z.number());
@@ -358,12 +360,9 @@ export function initialize_custom_date_type_fields(
// outside while the calendar popover is closed.
$(element_id)
.find<HTMLInputElement>("input.date-field-alt-input")
- .on("change", function (this: HTMLInputElement) {
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
- const $datepicker = $(this).parent().find(".datepicker")[0] as HTMLInputElement & {
- _flatpickr: flatpickr.Instance;
- };
- const instance = $datepicker._flatpickr;
+ .on("change", function () {
+ const instance = the($(this).parent().find(".datepicker"))._flatpickr;
+ assert(instance !== undefined);
const date = new Date($(this).val()!);
const date_str = format_date(date, "Y-m-d");
update_date(instance, date_str);