Examples
The repository ships three minimal consumer projects under examples/, covering three common consumption scenarios:
web-ts: gadget in TypeScript
The gadget workflow: mw globals from types-mediawiki, response types declared with this package, bundled before deployment. src/index.ts demonstrates three shapes:
- Parsed wikitext (
action=parse). - Global usages of a file (
prop=globalusage, activated by a type-only import of the GlobalUsage pack, see Opt-in extension packs). - A token-guarded edit (
postWithToken).
Every result is typed with an as assertion; the imports are type-only and get erased by the bundler.
web-js: gadget in plain JavaScript
Same runtime environment, no build step: JSDoc provides the types and the IDE renders them on hover. The example shows two JSDoc idioms:
@typedefaliases.- The
/** @type {X} */cast that narrows the loose valuemw.Apiresolves to.
The tsconfig enables checkJs, so CI validates the JSDoc too.
node-bot: bot client on Node
There is no mw.Api global class like a MediaWiki page provides: a hand-rolled Bot class wraps fetch and takes the response type as a generic argument — request<ApiQueryResponse>({ action: "query", … }).
It covers the pieces a bot actually needs: a descriptive User-Agent, meta=tokens for the CSRF token, QueryPage<"revisions"> to scope query.pages to the requested props, and an edit.result check.
Try them
To check a single example: cd examples/web-ts && pnpm typecheck.