Skip to content

A platform for community discussion. Free, open, simple.

DEV: Type strict-narrowed members in models and services (#44652)

Sérgio Saquetimfc41b282f009
diff --git a/frontend/discourse/admin/models/admin-user.js b/frontend/discourse/admin/models/admin-user.js
index 5e343a532c5..f75328e05ac 100644
--- a/frontend/discourse/admin/models/admin-user.js
+++ b/frontend/discourse/admin/models/admin-user.js
@@ -16,7 +16,7 @@ export default class AdminUser extends User {
* @param {string|number} user_id - The ID of the user to be retrieved.
* @param {Object} [opts] - Options to customize the result format.
* @param {boolean} [opts.raw=false] - If true, returns the raw response instead of formatting it using AdminUser.create.
- * @return {Promise<Object|AdminUser>} A promise that resolves with either the raw response object or an instance of AdminUser.
+ * @return {Promise<Record<string, unknown>|AdminUser>} A promise that resolves with either the raw response object or an instance of AdminUser.
*/
static async find(user_id, opts = { raw: false }) {
const result = await ajax(`/admin/users/${user_id}.json`);
diff --git a/frontend/discourse/admin/models/report.js b/frontend/discourse/admin/models/report.js
index 99747f30c2d..5cd6cc95145 100644
--- a/frontend/discourse/admin/models/report.js
+++ b/frontend/discourse/admin/models/report.js
@@ -207,7 +207,11 @@ export default class Report extends EmberObject {
average = false;
percent = false;
higher_is_better = true;
+
+ /** @type {string | null} */
description_link = null;
+
+ /** @type {string | null} */
description = null;
@computed("type", "start_date", "end_date")
diff --git a/frontend/discourse/admin/models/site-setting.js b/frontend/discourse/admin/models/site-setting.js
index 3737a00e001..e20a833bb08 100644
--- a/frontend/discourse/admin/models/site-setting.js
+++ b/frontend/discourse/admin/models/site-setting.js
@@ -80,6 +80,8 @@ export default class SiteSetting extends EmberObject {
}
@tracked isSaving = false;
+
+ /** @type {string | import("@ember/template").TrustedHTML | null} */
@tracked validationMessage = null;
updateExistingUsers = false;
diff --git a/frontend/discourse/admin/models/web-hook.js b/frontend/discourse/admin/models/web-hook.js
index 22b8c877ea4..8cb157df734 100644
--- a/frontend/discourse/admin/models/web-hook.js
+++ b/frontend/discourse/admin/models/web-hook.js
@@ -44,7 +44,15 @@ export default class WebHook extends RestModel {
wildcard_web_hook = false;
verify_certificate = true;
active = false;
+
+ /** @type {Array<{ id: number, name: string }> | null} */
web_hook_event_types = null;
+
+ /**
+ * Group names, or a comma-separated string of them when set by a group selector.
+ *
+ * @type {string[] | string | null}
+ */
group_names = null;
@computed("wildcard_web_hook")
diff --git a/frontend/discourse/admin/services/admin-search-data-source.js b/frontend/discourse/admin/services/admin-search-data-source.js
index 85110bb70cb..cae911a82e9 100644
--- a/frontend/discourse/admin/services/admin-search-data-source.js
+++ b/frontend/discourse/admin/services/admin-search-data-source.js
@@ -22,6 +22,53 @@ const SEARCH_SCORES = {
pageBonusScore: 20,
};
+/**
+ * @typedef {object} AdminNavLink
+ * @property {string} [name]
+ * @property {string} [route]
+ * @property {unknown[]} [routeModels]
+ * @property {string} [href]
+ * @property {string} [label] Translation key, used when `text` is absent.
+ * @property {string} [text]
+ * @property {string} [keywords] Translation key for `|`-separated keywords.
+ * @property {string} [description] Translated text, or a translation key.
+ */
+
+/**
+ * @typedef {object} AdminNavSection
+ * @property {string} [label] Translation key, used when `text` is absent.
+ * @property {string} [text]
+ */
+
+/**
+ * @typedef {object} AdminSearchSetting
+ * @property {string} setting
+ * @property {string} [humanized_name]
+ * @property {string} [description]
+ * @property {string[]} [keywords]
+ * @property {string} [plugin]
+ * @property {string | null} [primary_area]
+ * @property {string} [category]
+ */
+
+/**
+ * @typedef {object} AdminSearchPlugin
+ * @property {{ label?: string, location: string, use_new_show_route?: boolean }} admin_route
+ */
+
+/**
+ * @typedef {object} AdminSettingPageMap
+ * @property {Record<string, string>} categories URL of each settings category page.
+ * @property {Record<string, string>} areas URL of each config area page.
+ */
+
+/**
+ * @typedef {object} AdminSearchUpcomingChange
+ * @property {string} setting
+ * @property {string} humanized_name
+ * @property {string} description
+ */
+
function labelOrText(obj, fallback = "") {
return obj.text || (obj.label ? i18n(obj.label) : fallback);
}
@@ -41,10 +88,10 @@ function buildKeywords(...keywords) {
export class PageLinkFormatter {
/**
* @param {DiscourseRouter} router - The ember router service
- * @param {Object} navMapSection - The section of the admin nav map that the link belongs to,
+ * @param {AdminNavSection | null} navMapSection - The section of the admin nav map that the link belongs to,
* used for the parent label.
- * @param {Object} link - The link object from the admin nav map, with name/route/label etc.
- * @param {String} parentLabel - The parent label of the link, if any, this should be translated.
+ * @param {AdminNavLink} link - The link object from the admin nav map, with name/route/label etc.
+ * @param {string | null} [parentLabel] - The parent label of the link, if any, this should be translated.
*/
constructor(router, navMapSection, link, parentLabel = null) {
this.router = router;
@@ -103,9 +150,9 @@ export class PageLinkFormatter {
export class SettingLinkFormatter {
/**
* @param {DiscourseRouter} router - The ember router service
- * @param {Object} setting - The setting object from the site settings API
- * @param {Object} plugins - The plugins object built from the visible plugins in preload store
- * @param {Object} settingPageMap - The setting page map object with categories and areas.
+ * @param {AdminSearchSetting} setting - The setting object from the site settings API
+ * @param {Record<string, AdminSearchPlugin>} plugins - The plugins object built from the visible plugins in preload store
+ * @param {AdminSettingPageMap} settingPageMap - The setting page map object with categories and areas.
* This points to the URL of the relevant setting page
*/
constructor(router, setting, plugins, settingPageMap) {
@@ -205,7 +252,7 @@ export class SettingLinkFormatter {
export class UpcomingChangeLinkFormatter {
/**
- * @param {Object} upcomingChange - The upcoming change object from the upcoming changes API
+ * @param {AdminSearchUpcomingChange} upcomingChange - The upcoming change object from the upcoming changes API
*/
constructor(upcomingChange) {
this.upcomingChange = upcomingChange;
diff --git a/frontend/discourse/dialog-holder/services/dialog.js b/frontend/discourse/dialog-holder/services/dialog.js
index 02a188e820c..cd1e8559223 100644
--- a/frontend/discourse/dialog-holder/services/dialog.js
+++ b/frontend/discourse/dialog-holder/services/dialog.js
@@ -1,27 +1,64 @@
import Service from "@ember/service";
import { bind } from "discourse/lib/decorators";
+/**
+ * @typedef {object} DialogButton
+ * @property {string} label
+ * @property {string} [icon]
+ * @property {string} [class]
+ * @property {() => unknown} [action]
+ */
+
export default class DialogService extends Service {
dialogInstance = null;
+
+ /** @type {string | import("@ember/template").TrustedHTML | null | undefined} */
message = null;
+
+ /** @type {string | null | undefined} */
title = null;
+
+ /** @type {"dialog-title" | null} */
titleElementId = null;
+
+ /** @type {string | null | undefined} */
type = null;
+ /** @type {import("@glint/template").ComponentLike<{ Args: { model: unknown } }> | null | undefined} */
bodyComponent = null;
+
+ /** @type {unknown} */
bodyComponentModel = null;
+ /** @type {string | null | undefined} */
confirmButtonIcon = null;
+
+ /** @type {string | null} */
confirmButtonLabel = null;
+
+ /** @type {string | null} */
confirmButtonClass = null;
confirmButtonDisabled = false;
+
+ /** @type {string | null} */
cancelButtonLabel = null;
+
+ /** @type {string | null} */
cancelButtonClass = null;
+
+ /** @type {boolean | null | undefined} */
shouldDisplayCancel = null;
+ /** @type {(() => void) | null | undefined} */
didConfirm = null;
+
+ /** @type {(() => void) | null | undefined} */
didCancel = null;
+
+ /** @type {DialogButton[] | null | undefined} */
buttons = null;
+
+ /** @type {string | null | undefined} */
class = null;
_confirming = false;