WeChat Mini Program API Typings

repository·master·Indexed 21 days ago

https://github.com/wechat-miniprogram/api-typings

TypeScript type definitions for the WeChat Mini Program API, providing type safety and autocompletion. Available as a standalone npm package or via @types/wechat-miniprogram. Includes auto-generated API definitions from official documentation and manual definitions for Page and Component interfaces.

Tokens
997
Snippets
4
Records
6
Agent score
74%

What's inside miniprogram-api-typings

  1. Configure miniprogram-api-typings in your project

    master

    If you installed the standalone miniprogram-api-typings package, you must tell TypeScript how to use it. You can use any of the following three methods:

    1. Manual Import: Add an import statement in your entry file.
    2. tsconfig.json: Add the package to your types array (recommended for global availability).
    3. Triple-slash Directive: Reference the definition file directly in a specific file.
    // Method 1: Manual import
    import 'miniprogram-api-typings';
    
    // Method 2: In tsconfig.json
    // {
    //   "compilerOptions": {
    //     "types": ["miniprogram-api-typings"]
    //   }
    // }
    
    // Method 3: Triple-slash directive
    /// <reference path="node_modules/miniprogram-api-typings/index.d.ts" />
  2. Configure TypeScript to use miniprogram-api-typings

    master

    After installing the miniprogram-api-typings standalone package, you must ensure TypeScript recognizes the definitions. You can use any of the following three methods:

    1. Manual Import: Add an import statement in your entry file.
    2. tsconfig.json: Add the package to your types array.
    3. Triple-Slash Directive: Reference the declaration file directly in a specific file.
    // Method 1: Manual import
    import 'miniprogram-api-typings';
    
    // Method 2: tsconfig.json
    // { "compilerOptions": { "types": ["miniprogram-api-typings"] } }
    
    // Method 3: Triple-Slash Directive
    /// <reference path="node_modules/miniprogram-api-typings/index.d.ts" />
  3. How to contribute to API definitions

    master

    The repository distinguishes between auto-generated API definitions and manually written definitions:

    • Auto-generated APIs (lib.wx.api.d.ts): These are generated from official documentation. Do not submit PRs to modify this file. If you find an error in an API definition, please open an Issue instead.
    • Manual Definitions: Definitions for Page, Component, and other structures are written manually. Contributions via Pull Requests (PRs) or Issues for these files are encouraged.
  4. Reporting API definition errors

    master

    The core API definition file (lib.wx.api.d.ts) is automatically generated from the official WeChat Mini Program documentation.

    • If you find an error in an API interface definition: Please open an issue. Note that Pull Requests (PRs) for API definitions will not be accepted because they are auto-generated.
    • If you find bugs or have suggestions for Page, Component, or other interfaces: You are welcome to submit a Pull Request or open an issue.
  5. Install Wechat Mini Program API Typings

    master

    You can install the Wechat Mini Program type definitions using either the standalone npm package or via DefinitelyTyped.

    Option 1: Standalone npm package

    This is the primary method using the miniprogram-api-typings package.

    Option 2: DefinitelyTyped

    Install the types via the @types/wechat-miniprogram package.

    # Option 1: Standalone npm package
    npm install miniprogram-api-typings
    
    # Option 2: By DefinitelyTyped
    npm install @types/wechat-miniprogram
  6. Use the WeChat Mini Program API typings

    master

    To use the WeChat Mini Program type definitions in your TypeScript project, you should reference the main entry point. This package provides comprehensive type definitions for the WeChat Mini Program API surface. The main entry point redirects to the core type definitions located in ./types/index.d.ts.

    /// <reference path="./types/index.d.ts" />