diff --git a/tools/test-js-with-node b/tools/test-js-with-node index a47dedab76..4d4eeb4a3e 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -46,7 +46,7 @@ EXEMPT_FILES = make_set( [ "web/shared/src/poll_data.ts", "web/src/about_zulip.ts", - "web/src/add_stream_options_popover.js", + "web/src/add_stream_options_popover.ts", "web/src/add_subscribers_pill.js", "web/src/admin.js", "web/src/alert_popup.ts", diff --git a/web/src/add_stream_options_popover.js b/web/src/add_stream_options_popover.ts similarity index 71% rename from web/src/add_stream_options_popover.js rename to web/src/add_stream_options_popover.ts index 6011faaf01..ca5bc0a580 100644 --- a/web/src/add_stream_options_popover.js +++ b/web/src/add_stream_options_popover.ts @@ -1,4 +1,6 @@ import $ from "jquery"; +import assert from "minimalistic-assert"; +import type {ReferenceElement} from "tippy.js"; import render_left_sidebar_stream_setting_popover from "../templates/popovers/left_sidebar_stream_setting_popover.hbs"; @@ -6,7 +8,7 @@ import * as popover_menus from "./popover_menus"; import * as settings_data from "./settings_data"; import {parse_html} from "./ui_util"; -export function initialize() { +export function initialize(): void { popover_menus.register_popover_menu("#streams_inline_icon", { onShow(instance) { const can_create_streams = @@ -31,32 +33,41 @@ export function initialize() { // When showing the popover menu, we want the // "Add streams" and the "Filter streams" tooltip // to appear below the "Add streams" icon. - const add_streams_tooltip = $("#add_streams_tooltip").get(0); + const add_streams_tooltip: ReferenceElement | undefined = + $("#add_streams_tooltip").get(0); + assert(add_streams_tooltip !== undefined); add_streams_tooltip._tippy?.setProps({ placement: "bottom", }); - const filter_streams_tooltip = $("#filter_streams_tooltip").get(0); + + const filter_streams_tooltip: (ReferenceElement & HTMLElement) | undefined = + $("#filter_streams_tooltip").get(0); // If `filter_streams_tooltip` is not triggered yet, this will set its initial placement. + assert(filter_streams_tooltip !== undefined); filter_streams_tooltip.dataset.tippyPlacement = "bottom"; filter_streams_tooltip._tippy?.setProps({ placement: "bottom", }); - // The linter complains about unbalanced returns - return true; + return undefined; }, onHidden(instance) { instance.destroy(); - popover_menus.popover_instances.stream_settings = undefined; + popover_menus.popover_instances.stream_settings = null; // After the popover menu is closed, we want the // "Add streams" and the "Filter streams" tooltip // to appear at it's original position that is // above the "Add streams" icon. - const add_streams_tooltip = $("#add_streams_tooltip").get(0); + const add_streams_tooltip: ReferenceElement | undefined = + $("#add_streams_tooltip").get(0); + assert(add_streams_tooltip !== undefined); add_streams_tooltip._tippy?.setProps({ placement: "top", }); - const filter_streams_tooltip = $("#filter_streams_tooltip").get(0); + + const filter_streams_tooltip: (ReferenceElement & HTMLElement) | undefined = + $("#filter_streams_tooltip").get(0); + assert(filter_streams_tooltip !== undefined); filter_streams_tooltip.dataset.tippyPlacement = "top"; filter_streams_tooltip._tippy?.setProps({ placement: "top",