For AI agents: the complete documentation index is available at https://types-mediawiki-response.pages.dev/zh/llms.txt, the full documentation bundle is available at https://types-mediawiki-response.pages.dev/zh/llms-full.txt, and this page is available as Markdown at https://types-mediawiki-response.pages.dev/zh/index.md.
  • 中文
  • types-mediawiki-response

    MediaWiki Action API 响应的 TypeScript 类型

    纯类型,零运行时

    产物仅类型声明,不影响产物体积。

    跨版本支持

    覆盖 MediaWiki 1.39–1.47 的字段并集。

    JSDoc 覆盖

    每个字段标注参数与语义,IDE 悬停即文档。

    内置扩展,按需激活

    常用扩展的响应类型,一条 import 激活一个包。

    类型与文档悬浮即得

    类型按真实响应逐字段编写,JSDoc 标注每个字段的语义与来源参数。 在 IDE 里悬浮响应字段即可查看,不必翻文档。

    import type { ApiQueryResponse } from "types-mediawiki-response";
    
    const res = (await api.get({
      action: "query",
      meta: "siteinfo",
      siprop: "general",
      formatversion: "2",
    })) as ApiQueryResponse;
    
    const general = res.query.general;
    if (!general) throw new Error("missing query.general");
    
    console.log(`${general.sitename}: ${general.generator(property) ApiSiteGeneral.generator: stringGenerator, e.g. MediaWiki 1.43.0.}`);
    (property) ApiSiteGeneral.generator: stringGenerator, e.g. MediaWiki 1.43.0.

    编译期拦截错误

    类型和拼写错误在编译期由 TS 拦截。 更早一步发现错误,编辑器还会顺手给出正确拼写。

    import type { ApiQueryResponse } from "types-mediawiki-response";
    
    const res = (await api.get({
      action: "query",
      list: "search",
      srsearch: "insource:formatversion",
      formatversion: "2",
    })) as ApiQueryResponse;
    
    const [hit] = res.query.search ?? [];
    
    console.log(`${hit.title}: ${hit.snipetProperty 'snipet' does not exist on type 'ApiSearchHit'. Did you mean snippet?ts(2551)}`);
    $ tsc --noEmitapi.ts:12:34 - error TS2551: Property 'snipet' does not exist on type 'ApiSearchHit'. Did you mean 'snippet'?12 console.log(`${hit.title}: ${hit.snipet}`); ~~~~~~Found 1 error in api.ts:12