Skip to content

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

DEV: Convert session, login and small app models to TypeScript (#45198)

Sérgio Saquetim90c313996db1
diff --git a/frontend/discourse/app/models/badge-grouping.js b/frontend/discourse/app/models/badge-grouping.js
deleted file mode 100644
index 8bc2495ddcb..00000000000
--- a/frontend/discourse/app/models/badge-grouping.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import { computed } from "@ember/object";
-import RestModel from "discourse/models/rest";
-import { i18n } from "discourse-i18n";
-
-export function badgeGroupingDisplayName(name) {
- const i18nKey = `badges.badge_grouping.${name.toLowerCase().replace(/\s/g, "_")}.name`;
- return i18n(i18nKey, { defaultValue: name });
-}
-
-export default class BadgeGrouping extends RestModel {
- @computed("name")
- get i18nNameKey() {
- return this.name.toLowerCase().replace(/\s/g, "_");
- }
-
- @computed("name")
- get displayName() {
- return badgeGroupingDisplayName(this.name);
- }
-}
diff --git a/frontend/discourse/app/models/badge-grouping.ts b/frontend/discourse/app/models/badge-grouping.ts
new file mode 100644
index 00000000000..27bf3e64eb3
--- /dev/null
+++ b/frontend/discourse/app/models/badge-grouping.ts
@@ -0,0 +1,34 @@
+import { computed } from "@ember/object";
+import RestModel from "discourse/models/rest";
+import { i18n } from "discourse-i18n";
+
+export function badgeGroupingDisplayName(name: string): string {
+ const i18nKey = `badges.badge_grouping.${name.toLowerCase().replace(/\s/g, "_")}.name`;
+ return i18n(i18nKey, { defaultValue: name });
+}
+
+/** Serialized grouping data, plus the edit modal's optional row state. */
+export interface BadgeGroupingFields {
+ id: number;
+ name: string;
+ description: string | null;
+ position: number;
+ system: boolean;
+ editing?: boolean;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface BadgeGrouping extends BadgeGroupingFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class BadgeGrouping extends RestModel {
+ @computed("name")
+ get i18nNameKey(): string {
+ return this.name.toLowerCase().replace(/\s/g, "_");
+ }
+
+ @computed("name")
+ get displayName(): string {
+ return badgeGroupingDisplayName(this.name);
+ }
+}
diff --git a/frontend/discourse/app/models/category.ts b/frontend/discourse/app/models/category.ts
index dae0180105f..213a7864c3f 100644
--- a/frontend/discourse/app/models/category.ts
+++ b/frontend/discourse/app/models/category.ts
@@ -879,18 +879,17 @@ export default class Category extends RestModel {
}
@computed
- get availablePermissions() {
- // TODO(typescript-pending): PermissionType reads its create-assigned id but does not declare it.
+ get availablePermissions(): PermissionType[] {
return [
PermissionType.create({
id: PermissionType.FULL,
- } as Partial<PermissionType> & { id: number }),
+ }),
PermissionType.create({
id: PermissionType.CREATE_POST,
- } as Partial<PermissionType> & { id: number }),
+ }),
PermissionType.create({
id: PermissionType.READONLY,
- } as Partial<PermissionType> & { id: number }),
+ }),
];
}
diff --git a/frontend/discourse/app/models/form-template.js b/frontend/discourse/app/models/form-template.js
deleted file mode 100644
index b46c8de45e9..00000000000
--- a/frontend/discourse/app/models/form-template.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { ajax } from "discourse/lib/ajax";
-import RestModel from "discourse/models/rest";
-
-export default class FormTemplate extends RestModel {
- static async findAll() {
- const result = await ajax("/form-templates.json");
- return result.form_templates;
- }
-
- static async findById(id) {
- return await ajax(`/form-templates/${id}.json`);
- }
-}
diff --git a/frontend/discourse/app/models/form-template.ts b/frontend/discourse/app/models/form-template.ts
new file mode 100644
index 00000000000..be3e3c2ba7d
--- /dev/null
+++ b/frontend/discourse/app/models/form-template.ts
@@ -0,0 +1,26 @@
+import { ajax } from "discourse/lib/ajax";
+import RestModel from "discourse/models/rest";
+
+/** Plain JSON returned by the form-template endpoints, rather than a model instance. */
+export interface FormTemplatePayload {
+ id: number;
+ name: string;
+ template: string;
+}
+
+export default class FormTemplate extends RestModel {
+ static async findAll(): Promise<FormTemplatePayload[]> {
+ // TODO(typescript-pending): remove the response assertion when ajax supports typed payloads.
+ const result = (await ajax("/form-templates.json")) as {
+ form_templates: FormTemplatePayload[];
+ };
+ return result.form_templates;
+ }
+
+ /** Returns the entire show envelope, unlike the index factory's array. */
+ static async findById(
+ id: number
+ ): Promise<{ form_template: FormTemplatePayload }> {
+ return await ajax(`/form-templates/${id}.json`);
+ }
+}
diff --git a/frontend/discourse/app/models/live-post-counts.js b/frontend/discourse/app/models/live-post-counts.js
deleted file mode 100644
index 3dd8baf44c3..00000000000
--- a/frontend/discourse/app/models/live-post-counts.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import EmberObject from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-
-export default class LivePostCounts extends EmberObject {
- static find() {
- return ajax("/about/live_post_counts.json").then((result) =>
- LivePostCounts.create(result)
- );
- }
-}
diff --git a/frontend/discourse/app/models/live-post-counts.ts b/frontend/discourse/app/models/live-post-counts.ts
new file mode 100644
index 00000000000..c828e7ae09b
--- /dev/null
+++ b/frontend/discourse/app/models/live-post-counts.ts
@@ -0,0 +1,20 @@
+import EmberObject from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+
+/** Aggregate counts returned by the live counts endpoint. */
+export interface LivePostCountsFields {
+ public_topic_count: number;
+ public_post_count: number;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface LivePostCounts extends LivePostCountsFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class LivePostCounts extends EmberObject {
+ static find(): Promise<LivePostCounts> {
+ return ajax("/about/live_post_counts.json").then(
+ (result: LivePostCountsFields) => LivePostCounts.create(result)
+ );
+ }
+}
diff --git a/frontend/discourse/app/models/login-method.js b/frontend/discourse/app/models/login-method.ts
similarity index 59%
rename from frontend/discourse/app/models/login-method.js
rename to frontend/discourse/app/models/login-method.ts
index 07a4ed5375f..989da4a0ee1 100644
--- a/frontend/discourse/app/models/login-method.js
+++ b/frontend/discourse/app/models/login-method.ts
@@ -4,11 +4,26 @@ import { updateCsrfToken } from "discourse/lib/ajax";
import cookie from "discourse/lib/cookie";
import getURL from "discourse/lib/get-url";
import Session from "discourse/models/session";
-import Site from "discourse/models/site";
+import Site, { type SiteAuthProvider } from "discourse/models/site";
import { i18n } from "discourse-i18n";
+/** Provider payload plus optional client hooks and cached display flags. */
+export interface LoginMethodFields extends SiteAuthProvider {
+ /** Optional login hook; no production writer is currently known. */
+ customLogin?: () => void;
+ isGoogle?: boolean;
+ isDiscourseID?: boolean;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface LoginMethod extends LoginMethodFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export default class LoginMethod extends EmberObject {
- static buildPostForm(url, params = {}) {
+ static buildPostForm(
+ url: string,
+ params: Record<string, unknown> = {}
+ ): globalThis.Promise<HTMLFormElement> {
// Login always happens in an anonymous context, with no CSRF token
// So we need to fetch it before sending a POST request
return updateCsrfToken().then(() => {
@@ -19,13 +34,18 @@ export default class LoginMethod extends EmberObject {
const csrfInput = document.createElement("input");
csrfInput.setAttribute("name", "authenticity_token");
- csrfInput.setAttribute("value", Session.currentProp("csrfToken"));
+ // setAttribute coerces nullish tokens just as it does other form values.
+ csrfInput.setAttribute(
+ "value",
+ Session.currentProp("csrfToken") as string
+ );
form.appendChild(csrfInput);
Object.keys(params).forEach((key) => {
const input = document.createElement("input");
input.setAttribute("name", key);
- input.setAttribute("value", params[key]);
+ // Preserve the DOM's coercion of arbitrary authentication parameters.
+ input.setAttribute("value", params[key] as string);
form.appendChild(input);
});
@@ -36,17 +56,17 @@ export default class LoginMethod extends EmberObject {
}
@computed
- get title() {
+ get title(): string {
return this.title_override || i18n(`login.${this.name}.title`);
}
@computed
- get icon() {
+ get icon(): string {
return this.icon_override || "user";
}
@computed
- get screenReaderTitle() {
+ get screenReaderTitle(): string {
return (
this.title_override ||
i18n(`login.${this.name}.sr_title`, { defaultValue: this.title })
@@ -54,18 +74,28 @@ export default class LoginMethod extends EmberObject {
}
@computed
- get prettyName() {
+ get prettyName(): string {
return this.pretty_name_override || i18n(`login.${this.name}.name`);
}
- doLogin({ reconnect = false, signup = false, params = {} } = {}) {
+ /** Adds login flags, email and origin to the caller's params object in place. */
+ doLogin({
+ reconnect = false,
+ signup = false,
+ params = {},
+ }: {
+ reconnect?: boolean;
+ signup?: boolean;
+ params?: Record<string, unknown>;
+ } = {}): globalThis.Promise<void> {
if (this.customLogin) {
this.customLogin();
return Promise.resolve();
}
if (this.custom_url) {
- window.location = this.custom_url;
+ // Window's setter accepts a URL string; the global intersection obscures it.
+ (window as Window).location = this.custom_url;
return Promise.resolve();
}
@@ -93,9 +123,9 @@ export default class LoginMethod extends EmberObject {
}
}
-let methods;
+let methods: LoginMethod[] | undefined;
-export function findAll() {
+export function findAll(): LoginMethod[] {
if (methods) {
return methods;
}
@@ -112,6 +142,6 @@ export function findAll() {
return methods;
}
-export function clearAuthMethods() {
+export function clearAuthMethods(): void {
methods = undefined;
}
diff --git a/frontend/discourse/app/models/permission-type.js b/frontend/discourse/app/models/permission-type.js
deleted file mode 100644
index c5917f46ad3..00000000000
--- a/frontend/discourse/app/models/permission-type.js
+++ /dev/null
@@ -1,22 +0,0 @@
-import EmberObject, { computed } from "@ember/object";
-import { i18n } from "discourse-i18n";
-
-export function buildPermissionDescription(id) {
- return i18n("permission_types." + PermissionType.DESCRIPTION_KEYS[id]);
-}
-
-export default class PermissionType extends EmberObject {
- static FULL = 1;
- static CREATE_POST = 2;
- static READONLY = 3;
- static DESCRIPTION_KEYS = {
- 1: "full",
- 2: "create_post",
- 3: "readonly",
- };
-
- @computed("id")
- get description() {
- return buildPermissionDescription(this.id);
- }
-}
diff --git a/frontend/discourse/app/models/permission-type.ts b/frontend/discourse/app/models/permission-type.ts
new file mode 100644
index 00000000000..ce7102b2a06
--- /dev/null
+++ b/frontend/discourse/app/models/permission-type.ts
@@ -0,0 +1,31 @@
+import EmberObject, { computed } from "@ember/object";
+import { i18n } from "discourse-i18n";
+
+export function buildPermissionDescription(id: number): string {
+ return i18n("permission_types." + PermissionType.DESCRIPTION_KEYS[id]);
+}
+
+/** Client-assigned permission data. Plugins may augment these fields. */
+export interface PermissionTypeFields {
+ id: number;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface PermissionType extends PermissionTypeFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class PermissionType extends EmberObject {
+ static FULL = 1;
+ static CREATE_POST = 2;
+ static READONLY = 3;
+ static DESCRIPTION_KEYS: Record<number, string | undefined> = {
+ 1: "full",
+ 2: "create_post",
+ 3: "readonly",
+ };
+
+ @computed("id")
+ get description(): string {
+ return buildPermissionDescription(this.id);
+ }
+}
diff --git a/frontend/discourse/app/models/reviewable-history.js b/frontend/discourse/app/models/reviewable-history.js
deleted file mode 100644
index 0d734f3f3d9..00000000000
--- a/frontend/discourse/app/models/reviewable-history.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import RestModel from "discourse/models/rest";
-
-export const CLAIMED = 3;
-export const UNCLAIMED = 4;
-
-export default class ReviewableHistory extends RestModel {}
diff --git a/frontend/discourse/app/models/reviewable-history.ts b/frontend/discourse/app/models/reviewable-history.ts
new file mode 100644
index 00000000000..0d0be9df3df
--- /dev/null
+++ b/frontend/discourse/app/models/reviewable-history.ts
@@ -0,0 +1,22 @@
+import RestModel from "discourse/models/rest";
+import type User from "discourse/models/user";
+
+export const CLAIMED = 3 as const;
+export const UNCLAIMED = 4 as const;
+
+/** Server histories side-loaded with reviewables; synthetic timeline entries are separate. */
+export interface ReviewableHistoryFields {
+ id: number;
+ reviewable_history_type: number;
+ status: number;
+ created_at: string;
+ created_by_id?: number;
+ /** Hydration sets missing side-loaded creators to null. */
+ created_by?: User | null;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface ReviewableHistory extends ReviewableHistoryFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class ReviewableHistory extends RestModel {}
diff --git a/frontend/discourse/app/models/session.js b/frontend/discourse/app/models/session.js
deleted file mode 100644
index 1f94aa00cb1..00000000000
--- a/frontend/discourse/app/models/session.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { tracked } from "@glimmer/tracking";
-import singleton from "discourse/lib/singleton";
-import RestModel from "discourse/models/rest";
-
-// A data model representing current session data. You can put transient
-// data here you might want later. It is not stored or serialized anywhere.
-@singleton
-export default class Session extends RestModel {
- @tracked requiresRefresh = false;
-
- /** @type {boolean | null} */
- hasFocus = null;
-
- init() {
- this.set("highestSeenByTopic", {});
- }
-}
diff --git a/frontend/discourse/app/models/session.ts b/frontend/discourse/app/models/session.ts
new file mode 100644
index 00000000000..44aa9952dbb
--- /dev/null
+++ b/frontend/discourse/app/models/session.ts
@@ -0,0 +1,79 @@
+import { tracked } from "@glimmer/tracking";
+import singleton from "discourse/lib/singleton";
+import type Bookmark from "discourse/models/bookmark";
+import type CategoryList from "discourse/models/category-list";
+import RestModel from "discourse/models/rest";
+import type TopicList from "discourse/models/topic-list";
+
+/** Transient state assigned by boot and client consumers; never a server payload. */
+export interface SessionFields {
+ assetVersion?: string;
+ bookmarksModel?: {
+ bookmarks: Bookmark[];
+ loadMoreUrl?: string | null;
+ searchTerm?: string | null;
+ } | null;
+ csrfToken?: string | null;
+ darkModeAvailable?: boolean;
+ defaultColorSchemeIsDark?: boolean;
+ disableCustomCSS?: boolean;
+ /** Read during signup; no production writer is currently known. */
+ email?: string | null;
+ hideSignupCta?: boolean;
+ highestSeenByTopic: Record<number, number | null | undefined>;
+ highlightJsPath?: string;
+ mbLastFileChangeId?: number;
+ safe_mode?: string;
+ serviceWorkerURL?: string;
+ showSignupCta?: boolean;
+ svgSpritePath?: string;
+ topicList?: TopicList | CategoryList | null;
+ userColorSchemeId?: number;
+ userDarkSchemeId?: number;
+ [key: `user-menu-items:${string}`]: unknown[] | undefined;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface Session extends SessionFields {}
+
+/**
+ * A data model representing current session data. You can put transient
+ * data here you might want later. It is not stored or serialized anywhere.
+ */
+@singleton
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class Session extends RestModel {
+ /** Creates the default instance. Added by `@singleton`. */
+ declare static createCurrent: () => Session;
+
+ /** The session, created on first use. Added by `@singleton`. */
+ declare static current: () => Session;
+
+ /** Reads or sets a property; dynamic keys and property paths remain untyped. */
+ declare static currentProp: {
+ <K extends keyof Session>(property: K): Session[K];
+ <K extends keyof Session>(property: K, value: Session[K]): Session[K];
+ <P extends string>(
+ property: P extends keyof Session ? never : P,
+ value?: unknown
+ ): unknown;
+ };
+
+ /** Replaces the cached instance. Added by `@singleton`. */
+ declare static resetCurrent: <
+ T extends Session | null | undefined = undefined,
+ >(
+ value?: T
+ ) => T;
+
+ @tracked requiresRefresh = false;
+
+ hasFocus: boolean | null = null;
+
+ /** Cached instance managed by `@singleton`. */
+ declare static _current: Session | null | undefined;
+
+ init() {
+ this.set("highestSeenByTopic", {});
+ }
+}
diff --git a/frontend/discourse/app/models/static-page.js b/frontend/discourse/app/models/static-page.js
deleted file mode 100644
index 0764967d8c2..00000000000
--- a/frontend/discourse/app/models/static-page.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import EmberObject from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-
-export default class StaticPage extends EmberObject {
- // Models shouldn't really be doing Ajax request, but this is a huge speed boost if we
- // preload content.
- static async find(path) {
- const preloaded = document.querySelector(`noscript[data-path="/${path}"]`);
- if (preloaded) {
- const text = preloaded.textContent.match(
- /<!-- preload-content: -->((?:.|[\n\r])*)<!-- :preload-content -->/
- )[1];
- return StaticPage.create({ path, html: text });
- } else {
- const result = await ajax(`/${path}.html`, { dataType: "html" });
- return StaticPage.create({ path, html: result });
- }
- }
-}
diff --git a/frontend/discourse/app/models/static-page.ts b/frontend/discourse/app/models/static-page.ts
new file mode 100644
index 00000000000..ae26aae61fd
--- /dev/null
+++ b/frontend/discourse/app/models/static-page.ts
@@ -0,0 +1,31 @@
+import EmberObject from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+
+/** Successful static-page responses contain a path and HTML body. */
+export interface StaticPageFields {
+ path: string;
+ html: string;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface StaticPage extends StaticPageFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class StaticPage extends EmberObject {
+ /**
+ * Models shouldn't really be doing Ajax requests, but preloading content is a huge
+ * speed boost. The preload branch assumes non-null text and matching markers.
+ */
+ static async find(path: string): Promise<StaticPage> {
+ const preloaded = document.querySelector(`noscript[data-path="/${path}"]`);
+ if (preloaded) {
+ const text = preloaded.textContent!.match(
+ /<!-- preload-content: -->((?:.|[\n\r])*)<!-- :preload-content -->/
+ )![1];
+ return StaticPage.create({ path, html: text });
+ } else {
+ const result = await ajax(`/${path}.html`, { dataType: "html" });
+ return StaticPage.create({ path, html: result });
+ }
+ }
+}
diff --git a/frontend/discourse/app/models/trust-level.js b/frontend/discourse/app/models/trust-level.ts
similarity index 71%
rename from frontend/discourse/app/models/trust-level.js
rename to frontend/discourse/app/models/trust-level.ts
index 49a9ed9cc40..302099e8fff 100644
--- a/frontend/discourse/app/models/trust-level.js
+++ b/frontend/discourse/app/models/trust-level.ts
@@ -2,18 +2,21 @@ import { computed } from "@ember/object";
import { i18n } from "discourse-i18n";
export default class TrustLevel {
- constructor(id, key) {
+ declare id: number;
+ declare _key: string;
+
+ constructor(id: number, key: string) {
this.id = id;
this._key = key;
}
@computed
- get name() {
+ get name(): string {
return i18n(`trust_levels.names.${this._key}`);
}
@computed
- get detailedName() {
+ get detailedName(): string {
return i18n("trust_levels.detailed_name", {
level: this.id,
name: this.name,
diff --git a/frontend/discourse/app/services/store.ts b/frontend/discourse/app/services/store.ts
index 9083a0514e5..b6a57cdccbb 100644
--- a/frontend/discourse/app/services/store.ts
+++ b/frontend/discourse/app/services/store.ts
@@ -8,6 +8,7 @@ import { ajax } from "discourse/lib/ajax";
import { getRegister } from "discourse/lib/get-owner";
import { cleanNullQueryParams } from "discourse/lib/utilities";
import WeakValueMap from "discourse/lib/weak-value-map";
+import type BadgeGrouping from "discourse/models/badge-grouping";
import type Category from "discourse/models/category";
import type Composer from "discourse/models/composer";
import type Group from "discourse/models/group";
@@ -36,6 +37,7 @@ import type UserDraft from "discourse/models/user-draft";
/** Model instances by store type name. Plugins add theirs through module augmentation. */
export interface ModelRegistry {
+ "badge-grouping": BadgeGrouping;
category: Category;
composer: Composer;
group: Group;
diff --git a/frontend/discourse/type-tests/models/misc-test.ts b/frontend/discourse/type-tests/models/misc-test.ts
new file mode 100644
index 00000000000..f8fd56856ab
--- /dev/null
+++ b/frontend/discourse/type-tests/models/misc-test.ts
@@ -0,0 +1,260 @@
+import type EmberObject from "@ember/object";
+import { expectTypeOf } from "expect-type";
+import type { HelperContext } from "discourse/lib/helpers";
+import BadgeGrouping, {
+ badgeGroupingDisplayName,
+} from "discourse/models/badge-grouping";
+import type Category from "discourse/models/category";
+import type CategoryList from "discourse/models/category-list";
+import FormTemplate from "discourse/models/form-template";
+import LivePostCounts from "discourse/models/live-post-counts";
+import LoginMethod, {
+ clearAuthMethods,
+ findAll,
+} from "discourse/models/login-method";
+import PermissionType, {
+ buildPermissionDescription,
+} from "discourse/models/permission-type";
+import type RestModel from "discourse/models/rest";
+import ReviewableHistory, {
+ CLAIMED,
+ UNCLAIMED,
+} from "discourse/models/reviewable-history";
+import Session from "discourse/models/session";
+import StaticPage from "discourse/models/static-page";
+import type TopicList from "discourse/models/topic-list";
+import TrustLevel from "discourse/models/trust-level";
+import type User from "discourse/models/user";
+import type {
+ default as StoreService,
+ ModelFor,
+} from "discourse/services/store";
+
+declare const store: StoreService;
+declare const category: Category;
+declare const topicList: TopicList;
+declare const categoryList: CategoryList;
+declare const helperContext: HelperContext;
+
+declare module "discourse/models/session" {
+ interface SessionFields {
+ type_test_plugin_flag?: boolean;
+ }
+}
+
+declare module "discourse/models/login-method" {
+ interface LoginMethodFields {
+ type_test_plugin_flag?: boolean;
+ }
+}
+
+declare module "discourse/models/permission-type" {
+ interface PermissionTypeFields {
+ type_test_plugin_flag?: boolean;
+ }
+}
+
+declare module "discourse/models/badge-grouping" {
+ interface BadgeGroupingFields {
+ type_test_plugin_flag?: boolean;
+ }
+}
+
+/* Session: client-only state, never a server payload. */
+
+const session = Session.current();
+expectTypeOf(session).toEqualTypeOf<Session>();
+expectTypeOf(session).toExtend<RestModel>();
+expectTypeOf(helperContext.session).toEqualTypeOf<Session>();
+expectTypeOf(Session.resetCurrent()).toEqualTypeOf<undefined>();
+expectTypeOf(session.requiresRefresh).toEqualTypeOf<boolean>();
+expectTypeOf(session.hasFocus).toEqualTypeOf<boolean | null>();
+// Screen tracking records numbers; the topic controller resets entries to null.
+expectTypeOf(session.highestSeenByTopic[1]).toEqualTypeOf<
+ number | null | undefined
+>();
+// Discovery caches the last list, which the categories page fills with a CategoryList.
+expectTypeOf(session.topicList).toEqualTypeOf<
+ TopicList | CategoryList | null | undefined
+>();
+session.set("topicList", topicList);
+session.set("topicList", categoryList);
+session.set("topicList", null);
+// The meta tag can be missing, and a failed request clears the token to null.
+expectTypeOf(Session.currentProp("csrfToken")).toEqualTypeOf<
+ string | null | undefined
+>();
+Session.currentProp("csrfToken", "token");
+// @ts-expect-error the token is a string
+Session.currentProp("csrfToken", 1);
+// Boot copies these from the page's data attributes.
+expectTypeOf(session.userColorSchemeId).toEqualTypeOf<number | undefined>();
+expectTypeOf(session.userDarkSchemeId).toEqualTypeOf<number | undefined>();
+expectTypeOf(session.darkModeAvailable).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(session.highlightJsPath).toEqualTypeOf<string | undefined>();
+// Menus cache their items under keys built at runtime.
+Session.currentProp("user-menu-items:notifications", []);
+expectTypeOf(session["user-menu-items:notifications"]).toEqualTypeOf<
+ unknown[] | undefined
+>();
+expectTypeOf(Session.currentProp("runtime:cache")).toBeUnknown();
+Session.currentProp("runtime:cache", { items: [] });
+expectTypeOf(Session.createCurrent()).toEqualTypeOf<Session>();
+expectTypeOf(Session.resetCurrent(null)).toEqualTypeOf<null>();
+expectTypeOf(Session.resetCurrent(session)).toEqualTypeOf<Session>();
+expectTypeOf(Session.currentProp("type_test_plugin_flag")).toEqualTypeOf<
+ boolean | undefined
+>();
+expectTypeOf(session.bookmarksModel?.searchTerm).toEqualTypeOf<
+ string | null | undefined
+>();
+session.highestSeenByTopic[1] = null;
+
+/* TrustLevel: built by Site from `trust_levels`. */
+
+const trustLevel = new TrustLevel(1, "basic");
+expectTypeOf(trustLevel.id).toEqualTypeOf<number>();
+expectTypeOf(trustLevel.name).toEqualTypeOf<string>();
+expectTypeOf(trustLevel.detailedName).toEqualTypeOf<string>();
+// @ts-expect-error ids are numbers
+expectTypeOf(new TrustLevel("1", "basic")).toEqualTypeOf<TrustLevel>();
+
+/* PermissionType: synthesized client-side from a permission number. */
+
+expectTypeOf(PermissionType.FULL).toEqualTypeOf<number>();
+expectTypeOf(PermissionType.CREATE_POST).toEqualTypeOf<number>();
+expectTypeOf(PermissionType.READONLY).toEqualTypeOf<number>();
+expectTypeOf(PermissionType.DESCRIPTION_KEYS[1]).toEqualTypeOf<
+ string | undefined
+>();
+const permission = PermissionType.create({ id: PermissionType.FULL });
+expectTypeOf(permission).toExtend<EmberObject>();
+expectTypeOf(permission.id).toEqualTypeOf<number>();
+expectTypeOf(permission.description).toEqualTypeOf<string>();
+expectTypeOf(buildPermissionDescription(2)).toEqualTypeOf<string>();
+expectTypeOf(category.availablePermissions).toEqualTypeOf<PermissionType[]>();
+// @ts-expect-error permission ids are numbers
+PermissionType.create({ id: "1" });
+// The constants are writable statics.
+PermissionType.FULL = 1;
+PermissionType.DESCRIPTION_KEYS[99] = "custom";
+expectTypeOf(
+ PermissionType.create({ id: 1, type_test_plugin_flag: true })
+ .type_test_plugin_flag
+).toBeBoolean();
+
+/* LoginMethod: Site's `auth_providers`. */
+
+const methods = findAll();
+expectTypeOf(methods).toEqualTypeOf<LoginMethod[]>();
+clearAuthMethods();
+const method = methods[0];
+expectTypeOf(method).toExtend<EmberObject>();
+expectTypeOf(method.name).toEqualTypeOf<string>();
+expectTypeOf(method.can_connect).toEqualTypeOf<boolean>();
+expectTypeOf(method.can_revoke).toEqualTypeOf<boolean>();
+// Unset provider options serialize as null.
+expectTypeOf(method.custom_url).toEqualTypeOf<string | null>();
+expectTypeOf(method.frame_height).toEqualTypeOf<number | null>();
+expectTypeOf(method.frame_width).toEqualTypeOf<number | null>();
+expectTypeOf(method.icon_override).toEqualTypeOf<string | null>();
+expectTypeOf(method.pretty_name_override).toEqualTypeOf<string | null>();
+expectTypeOf(method.provider_url).toEqualTypeOf<string | null>();
+expectTypeOf(method.title_override).toEqualTypeOf<string | null>();
+// Set by findAll only.
+expectTypeOf(method.isGoogle).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(method.isDiscourseID).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(method.title).toEqualTypeOf<string>();
+expectTypeOf(method.icon).toEqualTypeOf<string>();
+expectTypeOf(method.screenReaderTitle).toEqualTypeOf<string>();
+expectTypeOf(method.prettyName).toEqualTypeOf<string>();
+// A plugin hides an existing provider's connect button.
+method.can_connect = false;
+method.set("can_connect", false);
+expectTypeOf<
+ Awaited<ReturnType<LoginMethod["doLogin"]>>
+>().toEqualTypeOf<void>();
+method.doLogin();
+method.doLogin({ signup: true });
+method.doLogin({ reconnect: true });
+method.doLogin({ signup: true, params: { origin: "/t/1" } });
+// @ts-expect-error signup is a flag
+method.doLogin({ signup: "yes" });
+expectTypeOf<
+ Awaited<ReturnType<typeof LoginMethod.buildPostForm>>
+>().toEqualTypeOf<HTMLFormElement>();
+LoginMethod.buildPostForm("/auth/github");
+LoginMethod.buildPostForm("/auth/github", { origin: "/t/1" });
+method.custom_url = null;
+method.customLogin = () => {};
+expectTypeOf(method.customLogin).toEqualTypeOf<() => void>();
+method.doLogin({ params: { signup: true, attempt: 1, absent: null } });
+expectTypeOf<LoginMethod["type_test_plugin_flag"]>().toEqualTypeOf<
+ boolean | undefined
+>();
+
+/* LivePostCounts: `/about/live_post_counts.json`. */
+
+declare const counts: Awaited<ReturnType<typeof LivePostCounts.find>>;
+expectTypeOf(counts).toEqualTypeOf<LivePostCounts>();
+expectTypeOf(counts.public_topic_count).toEqualTypeOf<number>();
+expectTypeOf(counts.public_post_count).toEqualTypeOf<number>();
+
+/* StaticPage: preloaded markup or `/:path.html`. */
+
+StaticPage.find("faq");
+declare const page: Awaited<ReturnType<typeof StaticPage.find>>;
+expectTypeOf(page).toEqualTypeOf<StaticPage>();
+expectTypeOf(page.path).toEqualTypeOf<string>();
+expectTypeOf(page.html).toEqualTypeOf<string>();
+
+/* BadgeGrouping: admin badge groupings. */
+
+expectTypeOf<ModelFor<"badge-grouping">>().toEqualTypeOf<BadgeGrouping>();
+const grouping = store.createRecord("badge-grouping", {
+ editing: true,
+ name: "Community",
+});
+expectTypeOf(grouping).toEqualTypeOf<BadgeGrouping>();
+expectTypeOf(grouping.id).toEqualTypeOf<number>();
+expectTypeOf(grouping.name).toEqualTypeOf<string>();
+expectTypeOf(grouping.description).toEqualTypeOf<string | null>();
+expectTypeOf(grouping.position).toEqualTypeOf<number>();
+expectTypeOf(grouping.system).toEqualTypeOf<boolean>();
+// The edit modal tracks which rows are open.
+expectTypeOf(grouping.editing).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(grouping.displayName).toEqualTypeOf<string>();
+expectTypeOf(grouping.i18nNameKey).toEqualTypeOf<string>();
+expectTypeOf(badgeGroupingDisplayName("Community")).toEqualTypeOf<string>();
+BadgeGrouping.create({ id: 1, name: "Community", description: null });
+expectTypeOf<BadgeGrouping["type_test_plugin_flag"]>().toEqualTypeOf<
+ boolean | undefined
+>();
+expectTypeOf<ModelFor<"BadgeGrouping">>().toEqualTypeOf<BadgeGrouping>();
+expectTypeOf<ModelFor<"badge_grouping">>().toEqualTypeOf<BadgeGrouping>();
+
+/* FormTemplate: the factories return plain JSON, not instances. */
+
+expectTypeOf<Awaited<ReturnType<typeof FormTemplate.findAll>>>().toEqualTypeOf<
+ { id: number; name: string; template: string }[]
+>();
+FormTemplate.findById(83);
+expectTypeOf<
+ Awaited<ReturnType<typeof FormTemplate.findById>>
+>().toEqualTypeOf<{
+ form_template: { id: number; name: string; template: string };
+}>();
+
+/* ReviewableHistory: side-loaded with reviewables. */
+
+expectTypeOf(CLAIMED).toEqualTypeOf<3>();
+expectTypeOf(UNCLAIMED).toEqualTypeOf<4>();
+declare const history: ReviewableHistory;
+expectTypeOf(history).toExtend<RestModel>();
+expectTypeOf(history.id).toEqualTypeOf<number>();
+expectTypeOf(history.reviewable_history_type).toEqualTypeOf<number>();
+expectTypeOf(history.status).toEqualTypeOf<number>();
+expectTypeOf(history.created_at).toEqualTypeOf<string>();
+// Hydration sets a creator missing from the side-load to null.
+expectTypeOf(history.created_by).toEqualTypeOf<User | null | undefined>();
+expectTypeOf(history.created_by_id).toEqualTypeOf<number | undefined>();