Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global typings for extensions #2992

Merged
merged 14 commits into from
Aug 19, 2021
Prev Previous commit
Next Next commit
Add flarum global variable
  • Loading branch information
davwheat authored Aug 9, 2021
commit 428bfff78c387f1d25a2add87923ff6d2e081492
32 changes: 32 additions & 0 deletions js/src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ declare const app: never;
declare const m: import('mithril').Static;
declare const dayjs: typeof import('dayjs');

type ESModule = { __esModule: true, [key: string]: unknown };

/**
* The global `flarum` variable.
*
* Contains the compiled ES Modules for all Flarum extensions and core.
*
* @example <caption>Check if `flarum-tags` is active.</captions>
* if ('flarum-tags' in flarum.extensions) {
* // Tags is enabled
* }
*/
interface FlarumObject {
/**
* Contains the compiled ES Module for Flarum's core.
*
* You shouldn't need to access this directly
*/
core: Readonly<ESModule>,
/**
* Contains the compiled ES Modules for all Flarum extensions.
*
* @example <caption>Check if `flarum-tags` is active.</captions>
* if ('flarum-tags' in flarum.extensions) {
* // Tags is enabled
* }
*/
extensions: Readonly<Record<string, ESModule>>,
}

declare const flarum: FlarumObject;

// Extend JQuery with our custom functions, defined with $.fn
interface JQuery {
/**
Expand Down