1
0
mirror of https://github.com/flarum/core.git synced 2025-08-05 16:07:34 +02:00

TS: Document shims files

This commit is contained in:
Franz Liedke
2020-09-18 15:11:27 +02:00
parent e10ebf0489
commit d572200cfb
2 changed files with 24 additions and 0 deletions

7
js/shims.d.ts vendored
View File

@@ -1,7 +1,14 @@
// Use shared globals from flarum-webpack-config
// TEMPORARY: This will likely move to the flarum-webpack-config package.
export * from './webpack-config-shims'; export * from './webpack-config-shims';
import Application from './src/common/Application'; import Application from './src/common/Application';
/**
* Annotate the types of all global variables specific to flarum/core.
*
* IDEs can use this to typehint the globals.
*/
declare global { declare global {
const app: Application; const app: Application;
} }

View File

@@ -4,16 +4,33 @@ import Stream from 'mithril/stream';
import * as _dayjs from 'dayjs'; import * as _dayjs from 'dayjs';
import * as _$ from 'jquery'; import * as _$ from 'jquery';
// Helpers that flarum/core patches into Mithril
interface m extends Mithril.Static { interface m extends Mithril.Static {
prop: typeof Stream; prop: typeof Stream;
} }
/**
* flarum/core exposes several extensions globally:
*
* - jQuery for convenient DOM manipulation
* - Mithril for VDOM and components
* - dayjs for date/time operations
*
* Since these are already part of the global namespace, extensions won't need
* to (and should not) bundle these themselves.
*/
declare global { declare global {
const $: typeof _$; const $: typeof _$;
const m: m; const m: m;
const dayjs: typeof _dayjs; const dayjs: typeof _dayjs;
} }
/**
* Export Mithril typings globally.
*
* This lets us use these typings without an extra import everywhere we use
* Mithril in a TypeScript file.
*/
export as namespace Mithril; export as namespace Mithril;
export {}; export {};