Skip to content

TypeScript definitions for MediaWiki JS interface

License

Notifications You must be signed in to change notification settings

hsl0/types-mediawiki

 
 

Repository files navigation

NPM version Linter

types-mediawiki

TypeScript definitions for MediaWiki JS interface.

This package covers the functions and classes in the mw global object, as well a few jQuery plugins used in MediaWiki core. All commonly used parts of the interface are covered but as far as complete coverage is concerned, this is a work in progress.

Download stats

Usage

To use types from this package, run

npm i types-mediawiki

Edit your project's tsconfig.json file so that it includes

"include": [
  "./node_modules/types-mediawiki"
]

You should be all set! mw will be available in the global scope. There is no need to put any import statements in the TypeScript source files. This package includes @types/jquery as a dependency, so you don't need to install that separately.

If you find any errors or have suggestions for more specific typings, please open a PR or file an issue.

mw.config

Types for mw.config are included:

let NS = mw.config.get("wgNamespaceNumber"); // NS gets type number
let pageName = mw.config.get("wgPageName"); // pageName gets type string

mw.config entries added by MediaWiki extensions can also be used but their type is not known, so they need to be explicitly cast:

let namespaces = mw.config.get("pageTriageNamespaces") as number[];

(mw.config.get('pageTriageNamespaces') gets the type unknown without a cast.)

MediaWiki API parameters

This package also provides typings for API request parameters for the MediaWiki Action API. API endpoints defined in MediaWiki core and by a number of common extensions (the ones enabled on English Wikipedia) are covered. These aren't exported to the global scope, however. For usage, you need to import them. For example:

import type { ApiEditPageParams, ApiParseParams } from "types-mediawiki/api_params";

Since it is just a type import, it doesn't generate any JavaScript. Hence, such imports can also be used in non-modular applications.


TODO:

PRs Welcome

  • Add doc comments for mw.Title, mw.Uri, mw.storage, mw.language and mw.loader.
  • Add types for more jQuery plugins.

About

TypeScript definitions for MediaWiki JS interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%