What is miniprogram-api-typings?
The miniprogram-api-typings npm package provides TypeScript type definitions for the WeChat Mini Program API. It helps developers by offering type safety and autocompletion features when developing WeChat Mini Programs using TypeScript.
What are miniprogram-api-typings's main functionalities?
Network Requests
This feature allows you to make network requests to a specified URL. The code sample demonstrates how to make a GET request and handle the success and failure responses.
wx.request({
url: 'https://example.com/api',
method: 'GET',
success: (res) => {
console.log(res.data);
},
fail: (err) => {
console.error(err);
}
});
User Interface
This feature provides methods to interact with the user interface. The code sample shows how to display a toast notification with a success icon.
wx.showToast({
title: 'Hello, World!',
icon: 'success',
duration: 2000
});
Storage
This feature allows you to store and retrieve data locally. The code sample demonstrates how to set and get a storage item.
wx.setStorage({
key: 'username',
data: 'JohnDoe'
});
wx.getStorage({
key: 'username',
success: (res) => {
console.log(res.data);
}
});
Location
This feature provides methods to access the device's location. The code sample shows how to get the current geographical location of the device.
wx.getLocation({
type: 'wgs84',
success: (res) => {
console.log(res.latitude, res.longitude);
}
});
Other packages similar to miniprogram-api-typings
weapp-api-typings
The weapp-api-typings package provides TypeScript type definitions for the WeChat Mini Program API, similar to miniprogram-api-typings. It offers type safety and autocompletion features for developers using TypeScript in WeChat Mini Programs.
taro
Taro is a multi-end unified development framework that supports the use of React syntax to write WeChat Mini Programs. It provides a more comprehensive solution compared to miniprogram-api-typings, as it includes a framework for building cross-platform applications.
mpvue
Mpvue is a front-end framework for developing WeChat Mini Programs using Vue.js. It offers a different approach compared to miniprogram-api-typings by allowing developers to use Vue.js syntax and features in their Mini Programs.
微信小程序定义文件
English version

微信小程序 API 的 TypeScript 类型定义文件
安装
通过 DefinitelyTyped
npm install @types/wechat-miniprogram
或:
通过独立 npm 包
npm install miniprogram-api-typings
安装后手动导入:
import 'miniprogram-api-typings';
或者在 ts 配置中指定:
- 在
tsconfig.json
中指定 types: ["miniprogram-api-typings"]
或者通过 三斜杠指令 引用:
/// <reference path="node_modules/miniprogram-api-typings/index.d.ts" />
更新日志
参考 CHANGELOG.md
贡献
API 的定义文件(lib.wx.api.d.ts
)是随 文档 一起自动生成的,如果发现了 API 接口的定义错误,请提一个 issue 给我们,关于 API 的 PR 将 不会 被接受。
如果有针对页面(Page
)、自定义组件(Component
)等接口的 bug 和建议,欢迎 PR 或提一个 issue 给我们。非常感谢!
贡献者
测试
本定义文件使用 tsd
进行测试,所有的测试样例放在 test
目录下。
想执行测试的话,克隆本项目并完成 npm install --save-dev
后执行 npm test
即可。
如果您发现了不能通过自动化测试的测试样例,可以提交 PR 或者提一个 issue。当然,能通过自动化测试的强有力的测试样例也是欢迎的。