index.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*! *****************************************************************************
  2. Copyright (c) 2023 Tencent, Inc. All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. ***************************************************************************** */
  19. /// <reference path="./lib.wx.app.d.ts" />
  20. /// <reference path="./lib.wx.page.d.ts" />
  21. /// <reference path="./lib.wx.api.d.ts" />
  22. /// <reference path="./lib.wx.cloud.d.ts" />
  23. /// <reference path="./lib.wx.canvas.d.ts" />
  24. /// <reference path="./lib.wx.component.d.ts" />
  25. /// <reference path="./lib.wx.behavior.d.ts" />
  26. /// <reference path="./lib.wx.event.d.ts" />
  27. declare namespace WechatMiniprogram {
  28. type IAnyObject = Record<string, any>
  29. type Optional<F> = F extends (arg: infer P) => infer R ? (arg?: P) => R : F
  30. type OptionalInterface<T> = { [K in keyof T]: Optional<T[K]> }
  31. interface AsyncMethodOptionLike {
  32. success?: (...args: any[]) => void
  33. }
  34. type PromisifySuccessResult<
  35. P,
  36. T extends AsyncMethodOptionLike
  37. > = P extends {
  38. success: any
  39. }
  40. ? void
  41. : P extends { fail: any }
  42. ? void
  43. : P extends { complete: any }
  44. ? void
  45. : Promise<Parameters<Exclude<T['success'], undefined>>[0]>
  46. // TODO: Extract real definition from `lib.dom.d.ts` to replace this
  47. type IIRFilterNode = any
  48. type WaveShaperNode = any
  49. type ConstantSourceNode = any
  50. type OscillatorNode = any
  51. type GainNode = any
  52. type BiquadFilterNode = any
  53. type PeriodicWaveNode = any
  54. type BufferSourceNode = any
  55. type ChannelSplitterNode = any
  56. type ChannelMergerNode = any
  57. type DelayNode = any
  58. type DynamicsCompressorNode = any
  59. type ScriptProcessorNode = any
  60. type PannerNode = any
  61. type AnalyserNode = any
  62. type AudioListener = any
  63. type WebGLTexture = any
  64. type WebGLRenderingContext = any
  65. // TODO: fill worklet type
  66. type WorkletFunction = (...args: any) => any
  67. type AnimationObject = any
  68. type SharedValue<T = any> = T
  69. type DerivedValue<T = any> = T
  70. }
  71. declare let console: WechatMiniprogram.Console
  72. declare let wx: WechatMiniprogram.Wx
  73. /** 引入模块。返回模块通过 `module.exports` 或 `exports` 暴露的接口。 */
  74. interface Require {
  75. (
  76. /** 需要引入模块文件相对于当前文件的相对路径,或 npm 模块名,或 npm 模块路径。不支持绝对路径 */
  77. module: string,
  78. /** 用于异步获取其他分包中的模块的引用结果,详见 [分包异步化]((subpackages/async)) */
  79. callback?: (moduleExport: any) => void,
  80. /** 异步获取分包失败时的回调,详见 [分包异步化]((subpackages/async)) */
  81. errorCallback?: (err: any) => void
  82. ): any
  83. /** 以 Promise 形式异步引入模块。返回模块通过 `module.exports` 或 `exports` 暴露的接口。 */
  84. async(
  85. /** 需要引入模块文件相对于当前文件的相对路径,或 npm 模块名,或 npm 模块路径。不支持绝对路径 */
  86. module: string
  87. ): Promise<any>
  88. }
  89. declare const require: Require
  90. /** 引入插件。返回插件通过 `main` 暴露的接口。 */
  91. interface RequirePlugin {
  92. (
  93. /** 需要引入的插件的 alias */
  94. module: string,
  95. /** 用于异步获取其他分包中的插件的引用结果,详见 [分包异步化]((subpackages/async)) */
  96. callback?: (pluginExport: any) => void
  97. ): any
  98. /** 以 Promise 形式异步引入插件。返回插件通过 `main` 暴露的接口。 */
  99. async(
  100. /** 需要引入的插件的 alias */
  101. module: string
  102. ): Promise<any>
  103. }
  104. declare const requirePlugin: RequirePlugin
  105. /** 插件引入当前使用者小程序。返回使用者小程序通过 [插件配置中 `export` 暴露的接口](https://developers.weixin.qq.com/miniprogram/dev/framework/plugin/using.html#%E5%AF%BC%E5%87%BA%E5%88%B0%E6%8F%92%E4%BB%B6)。
  106. *
  107. * 该接口只在插件中存在
  108. *
  109. * 最低基础库: `2.11.1` */
  110. declare function requireMiniProgram(): any
  111. /** 当前模块对象 */
  112. declare let module: {
  113. /** 模块向外暴露的对象,使用 `require` 引用该模块时可以获取 */
  114. exports: any
  115. }
  116. /** `module.exports` 的引用 */
  117. declare let exports: any
  118. /** [clearInterval(number intervalID)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/clearInterval.html)
  119. *
  120. * 取消由 setInterval 设置的定时器。 */
  121. declare function clearInterval(
  122. /** 要取消的定时器的 ID */
  123. intervalID: number
  124. ): void
  125. /** [clearTimeout(number timeoutID)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/clearTimeout.html)
  126. *
  127. * 取消由 setTimeout 设置的定时器。 */
  128. declare function clearTimeout(
  129. /** 要取消的定时器的 ID */
  130. timeoutID: number
  131. ): void
  132. /** [number setInterval(function callback, number delay, any rest)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/setInterval.html)
  133. *
  134. * 设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 */
  135. declare function setInterval(
  136. /** 回调函数 */
  137. callback: (...args: any[]) => any,
  138. /** 执行回调函数之间的时间间隔,单位 ms。 */
  139. delay?: number,
  140. /** param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */
  141. rest?: any
  142. ): number
  143. /** [number setTimeout(function callback, number delay, any rest)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/setTimeout.html)
  144. *
  145. * 设定一个定时器。在定时到期以后执行注册的回调函数 */
  146. declare function setTimeout(
  147. /** 回调函数 */
  148. callback: (...args: any[]) => any,
  149. /** 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 */
  150. delay?: number,
  151. /** param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */
  152. rest?: any
  153. ): number