Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
global: Specialize jQuery .val() for elements with known value types.
Anders Kaseorgeefd7feafaf9
diff --git a/web/src/global.d.ts b/web/src/global.d.tsindex 8635da6d55b..78b3f4aaf0b 100644--- a/web/src/global.d.ts+++ b/web/src/global.d.ts@@ -22,7 +22,21 @@ declare namespace JQueryValidation {}// eslint-disable-next-line @typescript-eslint/consistent-type-definitions-interface JQuery {+interface JQuery<TElement = HTMLElement> {+ // Specialize .val() for elements with known value types.+ // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/66801+ val():+ | (TElement extends HTMLSelectElement & {type: "select-one"}+ ? string+ : TElement extends HTMLSelectElement & {type: "select-multiple"}+ ? string[]+ : TElement extends HTMLSelectElement+ ? string | string[]+ : TElement extends {value: string | number}+ ? TElement["value"]+ : string | number | string[])+ | undefined;+expectOne(): this;get_offset_to_window(): DOMRect;tab(action?: string): this; // From web/third/bootstrapdiff --git a/web/src/rtl.ts b/web/src/rtl.tsindex 440c16db404..f5127fad9ae 100644--- a/web/src/rtl.ts+++ b/web/src/rtl.ts@@ -1,5 +1,4 @@import _ from "lodash";-import assert from "minimalistic-assert";// How to determine the direction of a paragraph (P1-P3): https://www.unicode.org/reports/tr9/tr9-35.html#The_Paragraph_Level// Embedding level: https://www.unicode.org/reports/tr9/tr9-35.html#BD2@@ -142,8 +141,7 @@ export function get_direction(str: string): "ltr" | "rtl" {export function set_rtl_class_for_textarea($textarea: JQuery<HTMLTextAreaElement>): void {// Set the rtl class if the text has an rtl direction, remove it otherwise- let text = $textarea.val();- assert(typeof text === "string", "Passed HTML element must be a textarea.");+ let text = $textarea.val()!;if (text.startsWith("```quote")) {text = text.slice(8);}