A platform for community discussion. Free, open, simple.
DEV: Improve types to unlock ember-tsc update (#39220)
Jarek Radosz8808444022ef
diff --git a/frontend/discourse/app/components/d-icon-grid-picker/content.gjs b/frontend/discourse/app/components/d-icon-grid-picker/content.gjsindex a2e434929d8..49e15f724b0 100644--- a/frontend/discourse/app/components/d-icon-grid-picker/content.gjs+++ b/frontend/discourse/app/components/d-icon-grid-picker/content.gjs@@ -10,7 +10,7 @@ import { modifier } from "ember-modifier";import AsyncContent from "discourse/components/async-content";import FilterInput from "discourse/components/filter-input";import concatClass from "discourse/helpers/concat-class";-import dIcon from "discourse/helpers/d-icon";+import icon from "discourse/helpers/d-icon";import withEventValue from "discourse/helpers/with-event-value";import { ajax } from "discourse/lib/ajax";import { eq } from "discourse/truth-helpers";@@ -32,6 +32,8 @@ const unfilteredIconCache = new Map();* current SVG sprite set. Defaults to true.*/export default class DIconGridPickerContent extends Component {+ /** @type {import("discourse/float-kit/services/tooltip").default} */+ // @ts-ignore (incorrect no-initialization error)@service tooltip;@tracked filter = "";@@ -146,10 +148,11 @@ export default class DIconGridPickerContent extends Component {return;}- const wrapper = target.closest(".d-icon-grid-picker__grid-wrapper");- const allIcons = /** @type {HTMLElement[]} */ ([- ...wrapper.querySelectorAll(".d-icon-grid-picker__icon"),- ]);+ const wrapper = /** @type {HTMLElement!} */ (+ target.closest(".d-icon-grid-picker__grid-wrapper")+ );+ const icons = wrapper.querySelectorAll(".d-icon-grid-picker__icon");+ const allIcons = /** @type {HTMLElement[]} */ ([...icons]);const idx = allIcons.indexOf(target);switch (event.key) {@@ -231,11 +234,15 @@ export default class DIconGridPickerContent extends Component {this.onGridKeyDown(event);}+ /**+ * @param {HTMLElement} wrapper+ */focusFilter(wrapper) {- wrapper- .closest(".d-icon-grid-picker__content")- ?.querySelector(".filter-input")- ?.focus();+ /** @type {HTMLInputElement?} */ (+ wrapper+ .closest(".d-icon-grid-picker__content")+ ?.querySelector(".filter-input")+ )?.focus();}get resultAnnouncement() {@@ -326,7 +333,7 @@ export default class DIconGridPickerContent extends Component {{{this.snapToGrid}}{{on "click" (fn @onSelect favIcon)}}>- {{dIcon favIcon}}+ {{icon favIcon}}{{#if @showSelectedName}}<spanclass="d-icon-grid-picker__selected-name"@@ -345,7 +352,7 @@ export default class DIconGridPickerContent extends Component {{{this.registerIconTooltip}}{{on "click" (fn @onSelect favIcon)}}>- {{dIcon favIcon}}+ {{icon favIcon}}</button>{{/if}}{{/each}}@@ -379,7 +386,7 @@ export default class DIconGridPickerContent extends Component {{{this.registerIconTooltip}}{{on "click" (fn @onSelect item.id)}}>- {{dIcon item.id}}+ {{icon item.id}}</button>{{/each}}</:content>diff --git a/frontend/discourse/app/components/d-icon-grid-picker/index.gjs b/frontend/discourse/app/components/d-icon-grid-picker/index.gjsindex 1f32ce4cf28..0d9ac721bfc 100644--- a/frontend/discourse/app/components/d-icon-grid-picker/index.gjs+++ b/frontend/discourse/app/components/d-icon-grid-picker/index.gjs@@ -10,42 +10,52 @@ import DIconGridPickerContent from "discourse/components/d-icon-grid-picker/cont/** @type {import("discourse/float-kit/components/d-menu.gjs").default} */import DMenu from "discourse/float-kit/components/d-menu";import concatClass from "discourse/helpers/concat-class";-import dIcon from "discourse/helpers/d-icon";+import icon from "discourse/helpers/d-icon";import { isValidHex, normalizeHex } from "discourse/lib/color-transformations";import { i18n } from "discourse-i18n";/**- * A grid-based icon picker that displays available icons in a searchable- * dropdown (desktop) or modal (mobile). Icons are fetched from the- * `/svg-sprite/picker-search` endpoint and rendered in a 12-column grid.+ * @typedef DIconGridPickerSignature*- * @param {string} value - The currently selected icon ID.- * @param {Function} onChange - Called with the selected icon ID when an icon is picked.- * @param {string[]} [favorites] - Icon IDs to display in a pinned favorites row above the grid.- * @param {boolean} [showSelectedName] - When true, the selected favorite chip also displays+ * @property {HTMLInputElement} Element+ * @property {object} Args+ *+ * @property {string} Args.value - The currently selected icon ID.+ * @property {Function} Args.onChange - Called with the selected icon ID when an icon is picked.+ * @property {string[]} [Args.favorites] - Icon IDs to display in a pinned favorites row above the grid.+ * @property {boolean} [Args.showSelectedName] - When true, the selected favorite chip also displays* the icon name alongside the icon.- * @param {string} [btnClass] - CSS class(es) for the trigger button. Defaults to "btn-default".- * @param {string} [label] - Optional text label shown next to the icon in the trigger button.- * @param {boolean} [allowClear] - When true, shows a clear button next to the trigger+ * @property {string} [Args.btnClass] - CSS class(es) for the trigger button. Defaults to "btn-default".+ * @property {string} [Args.label] - Optional text label shown next to the icon in the trigger button.+ * @property {boolean} [Args.allowClear] - When true, shows a clear button next to the trigger* in a split-button layout when a value is selected.- * @param {boolean} [showCaret] - When true, shows a chevron icon in the trigger+ * @property {boolean} [Args.showCaret] - When true, shows a chevron icon in the trigger* that flips between angle-down and angle-up based on the menu's expanded state.- * @param {boolean} [disabled] - When true, disables the trigger button and clear button.- * @param {boolean} [onlyAvailable] - When true, only shows icons available in the+ * @property {boolean} [Args.disabled] - When true, disables the trigger button and clear button.+ * @property {boolean} [Args.onlyAvailable] - When true, only shows icons available in the* current SVG sprite set. Defaults to true.- * @param {string} [iconColor] - CSS color value applied to icons in both the trigger+ * @property {string} [Args.iconColor] - CSS color value applied to icons in both the trigger* and the picker grid via the `--icon-color` custom property.- * @param {string} [selectedTitle] - Translation key for the trigger button title when an+ * @property {string} [Args.selectedTitle] - Translation key for the trigger button title when an* icon is selected. Receives `{iconName}` as an interpolation variable.* Defaults to "d_icon_grid_picker.selected_icon".- * @param {string} [clearTitle] - Translation key for the clear button title.+ * @property {string} [Args.clearTitle] - Translation key for the clear button title.* Defaults to "d_icon_grid_picker.clear".- * @param {boolean} [modalForMobile] - Whether to show as a modal on mobile. Defaults to true.- * @param {boolean} [inline] - When true, renders the menu inline instead of floating.- * @param {Function} [onShow] - Called when the picker menu is opened.- * @param {Function} [onClose] - Called when the picker menu is closed.+ * @property {boolean} [Args.modalForMobile] - Whether to show as a modal on mobile. Defaults to true.+ * @property {boolean} [Args.inline] - When true, renders the menu inline instead of floating.+ * @property {Function} [Args.onShow] - Called when the picker menu is opened.+ * @property {Function} [Args.onClose] - Called when the picker menu is closed.+ */++/**+ * A grid-based icon picker that displays available icons in a searchable+ * dropdown (desktop) or modal (mobile). Icons are fetched from the+ * `/svg-sprite/picker-search` endpoint and rendered in a 12-column grid.+ *+ * @extends {Component<DIconGridPickerSignature>}*/export default class DIconGridPicker extends Component {+ /** @type {import("discourse/float-kit/lib/d-menu-instance").default?} */@tracked menu = null;/**@@ -100,7 +110,7 @@ export default class DIconGridPicker extends Component {* Stores the DMenu API instance so the content can close the menu* programmatically after an icon is selected.*- * @param {Object} api - The DMenu API instance.+ * @param {import("discourse/float-kit/lib/d-menu-instance").default} api - The DMenu API instance.*/@actiononRegisterMenu(api) {@@ -161,7 +171,7 @@ export default class DIconGridPicker extends Component {><:trigger>{{#if @value}}- {{dIcon @value}}+ {{icon @value}}{{/if}}{{#if this.triggerLabel}}@@ -171,7 +181,7 @@ export default class DIconGridPicker extends Component {{{/if}}{{#if @showCaret}}- {{dIcon this.caretIcon class="d-icon-grid-picker__caret"}}+ {{icon this.caretIcon class="d-icon-grid-picker__caret"}}{{/if}}</:trigger><:content>diff --git a/frontend/discourse/app/components/d-otp/index.gjs b/frontend/discourse/app/components/d-otp/index.gjsindex 1e48bc4c6a3..57de263c56a 100644--- a/frontend/discourse/app/components/d-otp/index.gjs+++ b/frontend/discourse/app/components/d-otp/index.gjs@@ -17,6 +17,7 @@ const DEFAULT_SLOTS = 6;/*** @typedef DOTPSignature*+ * @property {HTMLInputElement} Element* @property {object} Args** @property {number} [Args.slots] - Number of OTP input slots to display (defaults to 6)@@ -28,6 +29,10 @@ const DEFAULT_SLOTS = 6;/** @extends {Component<DOTPSignature>} */export default class DOTP extends Component {+ /**+ * @type {import("discourse/services/capabilities").Capabilities}+ */+ // @ts-ignore (incorrect no-initialization error)@service capabilities;@tracked isFocused = false;@@ -51,9 +56,12 @@ export default class DOTP extends Component {return this.otp.join("");}+ /**+ * @param {InputEvent!} event+ */@actiononInput(event) {- const chars = event.target.value.split("");+ const chars = /** @type(HTMLInputElement) */ (event.target).value.split("");const wasFilled = this.isFilled;if (wasFilled && chars.length >= this.otp.length) {@@ -76,9 +84,12 @@ export default class DOTP extends Component {this.isAllSelected = false;}+ /**+ * @param {Event} event+ */@actiononSelect(event) {- const input = event.target;+ const input = /** @type {HTMLInputElement} */ (event.target);const hasSelection = input.selectionStart !== input.selectionEnd;this.isAllSelected =hasSelection &&@@ -98,6 +109,9 @@ export default class DOTP extends Component {this.isAllSelected = false;}+ /**+ * @param {KeyboardEvent} event+ */@actiononKeyDown(event) {// Disable arrow keys as you can only fill last unfilled or backspace@@ -108,9 +122,12 @@ export default class DOTP extends Component {}}+ /**+ * @param {ClipboardEvent} event+ */@actiononPaste(event) {- const input = event.target;+ const input = /** @type {HTMLInputElement} */ (event.target);event.preventDefault(); // Prevent the call to input as we manually call it laterconst { clipboardData } = event;@@ -120,9 +137,13 @@ export default class DOTP extends Component {const pastedData = clipboardData.getData("text");input.value = pastedData.replace(/[^0-9]/g, "");+ // @ts-ignorethis.onInput({ target: input });}+ /**+ * @param {number} index+ */@actionisFocusedSlot(index) {if (!this.isFocused) {diff --git a/frontend/discourse/app/services/capabilities.js b/frontend/discourse/app/services/capabilities.jsindex 7e2cdc9f256..8c46cb81dac 100644--- a/frontend/discourse/app/services/capabilities.js+++ b/frontend/discourse/app/services/capabilities.js@@ -13,7 +13,10 @@ const anyPointerCoarseQuery = new TrackedMediaQuery("(any-pointer: coarse)");let siteInitialized = false;-class Capabilities {+/**+ * @typedef {_Capabilities} Capabilities+ */+class _Capabilities {isAndroid = ua.includes("Android");isWinphone = ua.includes("Windows Phone");isIpadOS = ua.includes("Mac OS") && !/iPhone|iPod/.test(ua) && this.touch;@@ -135,7 +138,7 @@ class Capabilities {}}-export const capabilities = new Capabilities();+export const capabilities = new _Capabilities();export default class CapabilitiesServiceShim {static isServiceFactory = true;