interface PromisifyArgs { success?: (args: SuccessArg) => void; fail?: (args: FailArg) => void; } declare type Args = T & PromisifyArgs; interface Fn { (args: Args): void; } /** * 小程序API Promise化, 如果传递`success`或者`fail`也会继续调用回调函数. * * @template Arg fn参数类型. * @template SuccessArg `success`函数参数类型, 同`then`方法参数类型. * @template FailArg `fail`函数参数类型, 由于Promise catch方法参数被定义为`any`, `FailArg`泛型参数不能用于catch参数推断. * @param fn 小程序API函数. * @returns Promisified小程序API函数, 注: reject参数为小程序错误对象, * 小程序错误类型为纯对象`{ error: number; errorMessage: string; }`而非原生Error实例, * 访问[小程序前端 API 错误码对照表](https://opendocs.alipay.com/mini/00nmrr)了解更多. * @see https://zhuanlan.zhihu.com/p/123324774 * @see https://github.com/remaxjs/promise-mini-api/blob/master/promisify.ts */ declare function promisify(fn: Fn): (args?: Args | undefined) => Promise; export default promisify; export type { PromisifyArgs, Args, Fn };