@tarojs/taro 3.3.10 → 3.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/html5.css +5 -5
  2. package/package.json +5 -5
  3. package/types/api/ad/index.d.ts +34 -28
  4. package/types/api/alipay/index.d.ts +11 -7
  5. package/types/api/base/debug.d.ts +60 -54
  6. package/types/api/base/env.d.ts +12 -8
  7. package/types/api/base/index.d.ts +87 -83
  8. package/types/api/base/system.d.ts +59 -54
  9. package/types/api/base/update.d.ts +37 -33
  10. package/types/api/base/weapp/app-event.d.ts +147 -131
  11. package/types/api/base/weapp/life-cycle.d.ts +14 -10
  12. package/types/api/canvas/index.d.ts +115 -110
  13. package/types/api/cloud/index.d.ts +99 -94
  14. package/types/api/data-analysis/index.d.ts +72 -0
  15. package/types/api/device/accelerometer.d.ts +57 -50
  16. package/types/api/device/battery.d.ts +19 -15
  17. package/types/api/device/ble.d.ts +241 -228
  18. package/types/api/device/bluetooth.d.ts +207 -194
  19. package/types/api/device/clipboard.d.ts +48 -43
  20. package/types/api/device/compass.d.ts +55 -48
  21. package/types/api/device/contact.d.ts +13 -9
  22. package/types/api/device/gyroscope.d.ts +41 -35
  23. package/types/api/device/iBeacon.d.ts +79 -73
  24. package/types/api/device/motion.d.ts +42 -37
  25. package/types/api/device/network.d.ts +48 -42
  26. package/types/api/device/nfc.d.ts +105 -96
  27. package/types/api/device/performance.d.ts +22 -18
  28. package/types/api/device/phone.d.ts +20 -15
  29. package/types/api/device/scan.d.ts +31 -26
  30. package/types/api/device/screen.d.ts +74 -67
  31. package/types/api/device/vibrate.d.ts +31 -25
  32. package/types/api/device/wifi.d.ts +151 -140
  33. package/types/api/ext/index.d.ts +44 -39
  34. package/types/api/files/index.d.ts +219 -209
  35. package/types/api/framework/index.d.ts +25 -20
  36. package/types/api/location/index.d.ts +140 -136
  37. package/types/api/media/audio.d.ts +139 -127
  38. package/types/api/media/background-audio.d.ts +135 -126
  39. package/types/api/media/camera.d.ts +30 -26
  40. package/types/api/media/editor.d.ts +35 -33
  41. package/types/api/media/image.d.ts +190 -137
  42. package/types/api/media/live.d.ts +88 -82
  43. package/types/api/media/map.d.ts +47 -43
  44. package/types/api/media/recorder.d.ts +90 -84
  45. package/types/api/media/video-processing.d.ts +10 -6
  46. package/types/api/media/video.d.ts +63 -58
  47. package/types/api/network/download.d.ts +34 -30
  48. package/types/api/network/mdns.d.ts +104 -91
  49. package/types/api/network/request.d.ts +83 -79
  50. package/types/api/network/udp.d.ts +20 -16
  51. package/types/api/network/upload.d.ts +60 -56
  52. package/types/api/network/websocket.d.ts +201 -194
  53. package/types/api/open-api/account.d.ts +18 -14
  54. package/types/api/open-api/address.d.ts +27 -23
  55. package/types/api/open-api/authorize.d.ts +30 -26
  56. package/types/api/open-api/card.d.ts +55 -51
  57. package/types/api/open-api/customer-service.d.ts +45 -0
  58. package/types/api/open-api/facial.d.ts +28 -24
  59. package/types/api/open-api/invoice.d.ts +38 -34
  60. package/types/api/open-api/login.d.ts +56 -52
  61. package/types/api/open-api/navigate.d.ts +79 -75
  62. package/types/api/open-api/payment.d.ts +34 -30
  63. package/types/api/open-api/settings.d.ts +54 -45
  64. package/types/api/open-api/soter.d.ts +92 -86
  65. package/types/api/open-api/subscribe-message.d.ts +24 -20
  66. package/types/api/open-api/user-info.d.ts +60 -57
  67. package/types/api/open-api/werun.d.ts +50 -46
  68. package/types/api/route/index.d.ts +122 -118
  69. package/types/api/share/index.d.ts +68 -64
  70. package/types/api/storage/background-fetch.d.ts +40 -35
  71. package/types/api/storage/index.d.ts +267 -262
  72. package/types/api/swan/index.d.ts +47 -42
  73. package/types/api/ui/animation.d.ts +21 -17
  74. package/types/api/ui/background.d.ts +38 -34
  75. package/types/api/ui/custom-component.d.ts +22 -18
  76. package/types/api/ui/fonts.d.ts +26 -21
  77. package/types/api/ui/interaction.d.ts +167 -121
  78. package/types/api/ui/keyboard.d.ts +59 -55
  79. package/types/api/ui/menu.d.ts +10 -6
  80. package/types/api/ui/navigation-bar.d.ts +67 -63
  81. package/types/api/ui/pull-down-refresh.d.ts +33 -29
  82. package/types/api/ui/scroll.d.ts +30 -26
  83. package/types/api/ui/sticky.d.ts +22 -19
  84. package/types/api/ui/tab-bar.d.ts +101 -97
  85. package/types/api/ui/window.d.ts +24 -18
  86. package/types/api/worker/index.d.ts +28 -24
  87. package/types/api/wxml/index.d.ts +42 -38
  88. package/types/global.d.ts +350 -0
  89. package/types/index.d.ts +14 -99
  90. package/types/taro.api.d.ts +94 -0
  91. package/types/taro.component.d.ts +10 -57
  92. package/types/taro.config.d.ts +24 -6
  93. package/types/taro.extend.d.ts +70 -67
  94. package/types/taro.hooks.d.ts +68 -67
  95. package/types/taro.lifecycle.d.ts +47 -28
  96. package/types/api/ad/index.ts +0 -6
  97. package/types/api/alipay/index.ts +0 -7
  98. package/types/api/index.d.ts +0 -352
  99. package/types/api/open-api/data-analysis.d.ts +0 -19
  100. package/types/api/open-api/report.d.ts +0 -19
@@ -1,19 +1,16 @@
1
- declare namespace Taro {
2
- /** 停止搜索 mDNS 服务
3
- * @supported weapp
4
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.stopLocalServiceDiscovery.html
5
- */
6
- function stopLocalServiceDiscovery(option?: stopLocalServiceDiscovery.Option): void
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
7
4
  namespace stopLocalServiceDiscovery {
8
5
  interface Option {
9
6
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
10
- complete?: (res: General.CallbackResult) => void
7
+ complete?: (res: TaroGeneral.CallbackResult) => void
11
8
  /** 接口调用失败的回调函数 */
12
9
  fail?: (result: FailCallbackResult) => void
13
10
  /** 接口调用成功的回调函数 */
14
- success?: (res: General.CallbackResult) => void
11
+ success?: (res: TaroGeneral.CallbackResult) => void
15
12
  }
16
- interface FailCallbackResult extends General.CallbackResult {
13
+ interface FailCallbackResult extends TaroGeneral.CallbackResult {
17
14
  /** 错误信息
18
15
  *
19
16
  * 可选值:
@@ -21,26 +18,16 @@ declare namespace Taro {
21
18
  errMsg: string
22
19
  }
23
20
  }
24
-
25
- /** 开始搜索局域网下的 mDNS 服务。搜索的结果会通过 wx.onLocalService* 事件返回。
26
- *
27
- * **注意**
28
- * 1. wx.startLocalServiceDiscovery 是一个消耗性能的行为,开始 30 秒后会自动 stop 并执行 wx.onLocalServiceDiscoveryStop 注册的回调函数。
29
- * 2. 在调用 wx.startLocalServiceDiscovery 后,在这次搜索行为停止后才能发起下次 wx.startLocalServiceDiscovery。停止本次搜索行为的操作包括调用 wx.stopLocalServiceDiscovery 和 30 秒后系统自动 stop 本次搜索。
30
- * @supported weapp
31
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.startLocalServiceDiscovery.html
32
- */
33
- function startLocalServiceDiscovery(option: startLocalServiceDiscovery.Option): void
34
21
  namespace startLocalServiceDiscovery {
35
22
  interface Option {
36
23
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
37
- complete?: (res: General.CallbackResult) => void
24
+ complete?: (res: TaroGeneral.CallbackResult) => void
38
25
  /** 接口调用失败的回调函数 */
39
26
  fail?: (result: FailCallbackResult) => void
40
27
  /** 接口调用成功的回调函数 */
41
- success?: (res: General.CallbackResult) => void
28
+ success?: (res: TaroGeneral.CallbackResult) => void
42
29
  }
43
- interface FailCallbackResult extends General.CallbackResult {
30
+ interface FailCallbackResult extends TaroGeneral.CallbackResult {
44
31
  /** 错误信息
45
32
  *
46
33
  * 可选值:
@@ -50,14 +37,6 @@ declare namespace Taro {
50
37
  }
51
38
  }
52
39
 
53
- /** 监听 mDNS 服务解析失败的事件
54
- * @supported weapp
55
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceResolveFail.html
56
- */
57
- function onLocalServiceResolveFail(
58
- /** mDNS 服务解析失败的事件的回调函数 */
59
- callback: onLocalServiceResolveFail.Callback
60
- ): void
61
40
  namespace onLocalServiceResolveFail {
62
41
  /** mDNS 服务解析失败的事件的回调函数 */
63
42
  type Callback = (result: CallbackResult) => void
@@ -69,14 +48,6 @@ declare namespace Taro {
69
48
  }
70
49
  }
71
50
 
72
- /** 监听 mDNS 服务离开的事件
73
- * @supported weapp
74
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceLost.html
75
- */
76
- function onLocalServiceLost(
77
- /** mDNS 服务离开的事件的回调函数 */
78
- callback: onLocalServiceLost.Callback
79
- ): void
80
51
  namespace onLocalServiceLost {
81
52
  /** mDNS 服务离开的事件的回调函数 */
82
53
  type Callback = (result: CallbackResult) => void
@@ -88,14 +59,6 @@ declare namespace Taro {
88
59
  }
89
60
  }
90
61
 
91
- /** 监听 mDNS 服务发现的事件
92
- * @supported weapp
93
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceFound.html
94
- */
95
- function onLocalServiceFound(
96
- /** mDNS 服务发现的事件的回调函数 */
97
- callback: onLocalServiceFound.Callback
98
- ): void
99
62
  namespace onLocalServiceFound {
100
63
  /** mDNS 服务发现的事件的回调函数 */
101
64
  type Callback = (result: CallbackResult) => void
@@ -111,68 +74,118 @@ declare namespace Taro {
111
74
  }
112
75
  }
113
76
 
114
- /** 监听 mDNS 服务停止搜索的事件
115
- * @supported weapp
116
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceDiscoveryStop.html
117
- */
118
- function onLocalServiceDiscoveryStop(
119
- /** mDNS 服务停止搜索的事件的回调函数 */
120
- callback: onLocalServiceDiscoveryStop.Callback
121
- ): void
122
77
  namespace onLocalServiceDiscoveryStop {
123
78
  /** mDNS 服务停止搜索的事件的回调函数 */
124
- type Callback = (res: General.CallbackResult) => void
79
+ type Callback = (res: TaroGeneral.CallbackResult) => void
125
80
  }
126
81
 
127
- /** 取消监听 mDNS 服务解析失败的事件
128
- * @supported weapp
129
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceResolveFail.html
130
- */
131
- function offLocalServiceResolveFail(
132
- /** mDNS 服务解析失败的事件的回调函数 */
133
- callback: offLocalServiceResolveFail.Callback
134
- ): void
135
82
  namespace offLocalServiceResolveFail {
136
83
  /** mDNS 服务解析失败的事件的回调函数 */
137
- type Callback = (res: General.CallbackResult) => void
84
+ type Callback = (res: TaroGeneral.CallbackResult) => void
138
85
  }
139
86
 
140
- /** 取消监听 mDNS 服务离开的事件
141
- * @supported weapp
142
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceLost.html
143
- */
144
- function offLocalServiceLost(
145
- /** mDNS 服务离开的事件的回调函数 */
146
- callback: offLocalServiceLost.Callback
147
- ): void
148
87
  namespace offLocalServiceLost {
149
88
  /** mDNS 服务离开的事件的回调函数 */
150
- type Callback = (res: General.CallbackResult) => void
89
+ type Callback = (res: TaroGeneral.CallbackResult) => void
151
90
  }
152
91
 
153
- /** 取消监听 mDNS 服务发现的事件
154
- * @supported weapp
155
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceFound.html
156
- */
157
- function offLocalServiceFound(
158
- /** mDNS 服务发现的事件的回调函数 */
159
- callback: offLocalServiceFound.Callback
160
- ): void
161
92
  namespace offLocalServiceFound {
162
93
  /** mDNS 服务发现的事件的回调函数 */
163
- type Callback = (res: General.CallbackResult) => void
94
+ type Callback = (res: TaroGeneral.CallbackResult) => void
164
95
  }
165
96
 
166
- /** 取消监听 mDNS 服务停止搜索的事件
167
- * @supported weapp
168
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceDiscoveryStop.html
169
- */
170
- function offLocalServiceDiscoveryStop(
171
- /** mDNS 服务停止搜索的事件的回调函数 */
172
- callback: offLocalServiceDiscoveryStop.Callback
173
- ): void
174
97
  namespace offLocalServiceDiscoveryStop {
175
98
  /** mDNS 服务停止搜索的事件的回调函数 */
176
- type Callback = (res: General.CallbackResult) => void
99
+ type Callback = (res: TaroGeneral.CallbackResult) => void
100
+ }
101
+
102
+ interface TaroStatic {
103
+ /** 停止搜索 mDNS 服务
104
+ * @supported weapp
105
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.stopLocalServiceDiscovery.html
106
+ */
107
+ stopLocalServiceDiscovery(option?: stopLocalServiceDiscovery.Option): void
108
+
109
+ /** 开始搜索局域网下的 mDNS 服务。搜索的结果会通过 wx.onLocalService* 事件返回。
110
+ *
111
+ * **注意**
112
+ * 1. wx.startLocalServiceDiscovery 是一个消耗性能的行为,开始 30 秒后会自动 stop 并执行 wx.onLocalServiceDiscoveryStop 注册的回调函数。
113
+ * 2. 在调用 wx.startLocalServiceDiscovery 后,在这次搜索行为停止后才能发起下次 wx.startLocalServiceDiscovery。停止本次搜索行为的操作包括调用 wx.stopLocalServiceDiscovery 和 30 秒后系统自动 stop 本次搜索。
114
+ * @supported weapp
115
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.startLocalServiceDiscovery.html
116
+ */
117
+ startLocalServiceDiscovery(option: startLocalServiceDiscovery.Option): void
118
+
119
+ /** 监听 mDNS 服务解析失败的事件
120
+ * @supported weapp
121
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceResolveFail.html
122
+ */
123
+ onLocalServiceResolveFail(
124
+ /** mDNS 服务解析失败的事件的回调函数 */
125
+ callback: onLocalServiceResolveFail.Callback
126
+ ): void
127
+
128
+ /** 监听 mDNS 服务离开的事件
129
+ * @supported weapp
130
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceLost.html
131
+ */
132
+ onLocalServiceLost(
133
+ /** mDNS 服务离开的事件的回调函数 */
134
+ callback: onLocalServiceLost.Callback
135
+ ): void
136
+
137
+ /** 监听 mDNS 服务发现的事件
138
+ * @supported weapp
139
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceFound.html
140
+ */
141
+ onLocalServiceFound(
142
+ /** mDNS 服务发现的事件的回调函数 */
143
+ callback: onLocalServiceFound.Callback
144
+ ): void
145
+
146
+ /** 监听 mDNS 服务停止搜索的事件
147
+ * @supported weapp
148
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.onLocalServiceDiscoveryStop.html
149
+ */
150
+ onLocalServiceDiscoveryStop(
151
+ /** mDNS 服务停止搜索的事件的回调函数 */
152
+ callback: onLocalServiceDiscoveryStop.Callback
153
+ ): void
154
+
155
+ /** 取消监听 mDNS 服务解析失败的事件
156
+ * @supported weapp
157
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceResolveFail.html
158
+ */
159
+ offLocalServiceResolveFail(
160
+ /** mDNS 服务解析失败的事件的回调函数 */
161
+ callback: offLocalServiceResolveFail.Callback
162
+ ): void
163
+
164
+ /** 取消监听 mDNS 服务离开的事件
165
+ * @supported weapp
166
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceLost.html
167
+ */
168
+ offLocalServiceLost(
169
+ /** mDNS 服务离开的事件的回调函数 */
170
+ callback: offLocalServiceLost.Callback
171
+ ): void
172
+
173
+ /** 取消监听 mDNS 服务发现的事件
174
+ * @supported weapp
175
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceFound.html
176
+ */
177
+ offLocalServiceFound(
178
+ /** mDNS 服务发现的事件的回调函数 */
179
+ callback: offLocalServiceFound.Callback
180
+ ): void
181
+
182
+ /** 取消监听 mDNS 服务停止搜索的事件
183
+ * @supported weapp
184
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/mdns/wx.offLocalServiceDiscoveryStop.html
185
+ */
186
+ offLocalServiceDiscoveryStop(
187
+ /** mDNS 服务停止搜索的事件的回调函数 */
188
+ callback: offLocalServiceDiscoveryStop.Callback
189
+ ): void
177
190
  }
178
191
  }
@@ -1,20 +1,22 @@
1
- declare namespace Taro {
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
2
4
  namespace request {
3
- interface Option < U extends string | General.IAnyObject | ArrayBuffer = any | any > {
5
+ interface Option < U extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any > {
4
6
  /** 开发者服务器接口地址 */
5
7
  url: string
6
8
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
7
- complete?: (res: General.CallbackResult) => void
9
+ complete?: (res: TaroGeneral.CallbackResult) => void
8
10
  /** 请求的参数 */
9
11
  data?: U
10
12
  /** 返回的数据格式 */
11
13
  dataType?: keyof dataType | string
12
14
  /** 接口调用失败的回调函数 */
13
- fail?: (res: General.CallbackResult) => void
15
+ fail?: (res: TaroGeneral.CallbackResult) => void
14
16
  /** 设置请求的 header,header 中不能设置 Referer。
15
17
  *
16
18
  * `content-type` 默认为 `application/json` */
17
- header?: General.IAnyObject
19
+ header?: TaroGeneral.IAnyObject
18
20
  /** HTTP 请求方法 */
19
21
  method?: keyof method
20
22
  /** 响应的数据类型 */
@@ -65,11 +67,11 @@ declare namespace Taro {
65
67
  storeCheck?(): boolean
66
68
  }
67
69
 
68
- interface SuccessCallbackResult < T extends string | General.IAnyObject | ArrayBuffer = any | any > extends General.CallbackResult {
70
+ interface SuccessCallbackResult < T extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any > extends TaroGeneral.CallbackResult {
69
71
  /** 开发者服务器返回的数据 */
70
72
  data: T
71
73
  /** 开发者服务器返回的 HTTP Response Header */
72
- header: General.IAnyObject
74
+ header: TaroGeneral.IAnyObject
73
75
  /** 开发者服务器返回的 HTTP 状态码 */
74
76
  statusCode: number
75
77
  /** 调用结果 */
@@ -147,44 +149,10 @@ declare namespace Taro {
147
149
  }
148
150
  }
149
151
 
150
- /** 发起 HTTPS 网络请求。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
151
- *
152
- * **data 参数说明**
153
- * 最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。转换规则如下:
154
- * - 对于 `GET` 方法的数据,会将数据转换成 query string(`encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...`)
155
- * - 对于 `POST` 方法且 `header['content-type']` 为 `application/json` 的数据,会对数据进行 JSON 序列化
156
- * - 对于 `POST` 方法且 `header['content-type']` 为 `application/x-www-form-urlencoded` 的数据,会将数据转换成 query string `(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)`
157
- * @supported weapp, h5, rn, alipay, swan, tt, qq
158
- * @example
159
- * ```tsx
160
- * Taro.request({
161
- * url: 'test.php', //仅为示例,并非真实的接口地址
162
- * data: {
163
- * x: '',
164
- * y: ''
165
- * },
166
- * header: {
167
- * 'content-type': 'application/json' // 默认值
168
- * },
169
- * success: function (res) {
170
- * console.log(res.data)
171
- * }
172
- * })
173
- * ```
174
- * @example
175
- * async/await 用法:
176
- *
177
- * ```tsx
178
- * const res = await Taro.request(params)
179
- * ```
180
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
181
- */
182
- function request<T = any, U = any>(option: request.Option<U>): RequestTask<T>
183
-
184
152
  /** 网络请求任务对象
185
153
  * @example
186
154
  * 回调函数(Callback)用法:
187
- *
155
+ *
188
156
  * ```tsx
189
157
  * const requestTask = Taro.request({
190
158
  * url: 'test.php', //仅为示例,并非真实的接口地址
@@ -203,7 +171,7 @@ declare namespace Taro {
203
171
  * ```
204
172
  * @example
205
173
  * Promise 用法:
206
- *
174
+ *
207
175
  * ```tsx
208
176
  * const requestTask = Taro.request({
209
177
  * url: 'test.php', //仅为示例,并非真实的接口地址
@@ -225,7 +193,7 @@ declare namespace Taro {
225
193
  * ```
226
194
  * @example
227
195
  * async/await 用法:
228
- *
196
+ *
229
197
  * ```tsx
230
198
  * const requestTask = Taro.request(params)
231
199
  * const res = await requestTask
@@ -244,7 +212,7 @@ declare namespace Taro {
244
212
  */
245
213
  offHeadersReceived(
246
214
  /** HTTP Response Header 事件的回调函数 */
247
- callback: (res: General.CallbackResult) => void,
215
+ callback: (res: TaroGeneral.CallbackResult) => void,
248
216
  ): void
249
217
  /** 监听 HTTP Response Header 事件。会比请求完成事件更早
250
218
  * @supported weapp
@@ -259,41 +227,77 @@ declare namespace Taro {
259
227
  namespace RequestTask {
260
228
  interface OnHeadersReceivedCallbackResult {
261
229
  /** 开发者服务器返回的 HTTP Response Header */
262
- header: General.IAnyObject
230
+ header: TaroGeneral.IAnyObject
263
231
  }
264
232
  }
265
233
 
266
- /** 可以使用拦截器在请求发出前或发出后做一些额外操作。
267
- *
268
- * 在调用 `Taro.request` 发起请求之前,调用 `Taro.addInterceptor` 方法为请求添加拦截器,拦截器的调用顺序遵循洋葱模型。
269
- * 拦截器是一个函数,接受 chain 对象作为参数。chain 对象中含有 **requestParmas** 属性,代表请求参数。拦截器内最后需要调用 `chain.proceed(requestParams)` 以调用下一个拦截器或发起请求。
270
- *
271
- * Taro 提供了两个内置拦截器 `logInterceptor` `timeoutInterceptor`,分别用于打印请求的相关信息和在请求超时时抛出错误。
272
- * @supported weapp, h5, alipay, swan, tt, qq
273
- * @example
274
- * ```tsx
275
- * const interceptor = function (chain) {
276
- * const requestParams = chain.requestParams
277
- * const { method, data, url } = requestParams
278
- *
279
- * console.log(`http ${method || 'GET'} --> ${url} data: `, data)
280
- *
281
- * return chain.proceed(requestParams)
282
- * .then(res => {
283
- * console.log(`http <-- ${url} result:`, res)
284
- * return res
285
- * })
286
- * }
287
- * Taro.addInterceptor(interceptor)
288
- * Taro.request({ url })
289
- * ```
290
- * @example
291
- * ```tsx
292
- * Taro.addInterceptor(Taro.interceptors.logInterceptor)
293
- * Taro.addInterceptor(Taro.interceptors.timeoutInterceptor)
294
- * Taro.request({ url })
295
- * ```
296
- * @since 1.2.16
297
- */
298
- function addInterceptor (callback: Function): void
234
+ interface TaroStatic {
235
+ /** 发起 HTTPS 网络请求。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
236
+ *
237
+ * **data 参数说明**
238
+ * 最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。转换规则如下:
239
+ * - 对于 `GET` 方法的数据,会将数据转换成 query string(`encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...`)
240
+ * - 对于 `POST` 方法且 `header['content-type']` `application/json` 的数据,会对数据进行 JSON 序列化
241
+ * - 对于 `POST` 方法且 `header['content-type']` 为 `application/x-www-form-urlencoded` 的数据,会将数据转换成 query string `(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)`
242
+ * @supported weapp, h5, rn, alipay, swan, tt, qq
243
+ * @example
244
+ * ```tsx
245
+ * Taro.request({
246
+ * url: 'test.php', //仅为示例,并非真实的接口地址
247
+ * data: {
248
+ * x: '',
249
+ * y: ''
250
+ * },
251
+ * header: {
252
+ * 'content-type': 'application/json' // 默认值
253
+ * },
254
+ * success: function (res) {
255
+ * console.log(res.data)
256
+ * }
257
+ * })
258
+ * ```
259
+ * @example
260
+ * async/await 用法:
261
+ *
262
+ * ```tsx
263
+ * const res = await Taro.request(params)
264
+ * ```
265
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
266
+ */
267
+ request<T = any, U = any>(option: request.Option<U>): RequestTask<T>
268
+
269
+ /** 可以使用拦截器在请求发出前或发出后做一些额外操作。
270
+ *
271
+ * 在调用 `Taro.request` 发起请求之前,调用 `Taro.addInterceptor` 方法为请求添加拦截器,拦截器的调用顺序遵循洋葱模型。
272
+ * 拦截器是一个函数,接受 chain 对象作为参数。chain 对象中含有 **requestParmas** 属性,代表请求参数。拦截器内最后需要调用 `chain.proceed(requestParams)` 以调用下一个拦截器或发起请求。
273
+ *
274
+ * Taro 提供了两个内置拦截器 `logInterceptor` 与 `timeoutInterceptor`,分别用于打印请求的相关信息和在请求超时时抛出错误。
275
+ * @supported weapp, h5, alipay, swan, tt, qq
276
+ * @example
277
+ * ```tsx
278
+ * const interceptor = function (chain) {
279
+ * const requestParams = chain.requestParams
280
+ * const { method, data, url } = requestParams
281
+ *
282
+ * console.log(`http ${method || 'GET'} --> ${url} data: `, data)
283
+ *
284
+ * return chain.proceed(requestParams)
285
+ * .then(res => {
286
+ * console.log(`http <-- ${url} result:`, res)
287
+ * return res
288
+ * })
289
+ * }
290
+ * Taro.addInterceptor(interceptor)
291
+ * Taro.request({ url })
292
+ * ```
293
+ * @example
294
+ * ```tsx
295
+ * Taro.addInterceptor(Taro.interceptors.logInterceptor)
296
+ * Taro.addInterceptor(Taro.interceptors.timeoutInterceptor)
297
+ * Taro.request({ url })
298
+ * ```
299
+ * @since 1.2.16
300
+ */
301
+ addInterceptor (callback: Function): void
302
+ }
299
303
  }
@@ -1,10 +1,6 @@
1
- declare namespace Taro {
2
- /** 创建一个 UDP Socket 实例。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
3
- * @supported weapp
4
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/wx.createUDPSocket.html
5
- */
6
- function createUDPSocket(): UDPSocket
1
+ import Taro from '../../index'
7
2
 
3
+ declare module '../../index' {
8
4
  /** 一个 UDP Socket 实例,默认使用 IPv4 协议。
9
5
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.html
10
6
  */
@@ -36,7 +32,7 @@ declare namespace Taro {
36
32
  */
37
33
  offListening(
38
34
  /** 开始监听数据包消息的事件的回调函数 */
39
- callback: (res: General.CallbackResult) => void,
35
+ callback: (res: TaroGeneral.CallbackResult) => void,
40
36
  ): void
41
37
  /** 取消监听收到消息的事件
42
38
  * @supported weapp
@@ -44,7 +40,7 @@ declare namespace Taro {
44
40
  */
45
41
  offMessage(
46
42
  /** 收到消息的事件的回调函数 */
47
- callback: (res: General.CallbackResult) => void,
43
+ callback: (res: TaroGeneral.CallbackResult) => void,
48
44
  ): void
49
45
  /** 监听关闭事件
50
46
  * @supported weapp
@@ -68,7 +64,7 @@ declare namespace Taro {
68
64
  */
69
65
  onListening(
70
66
  /** 开始监听数据包消息的事件的回调函数 */
71
- callback: (res: General.CallbackResult) => void,
67
+ callback: (res: TaroGeneral.CallbackResult) => void,
72
68
  ): void
73
69
  /** 监听收到消息的事件
74
70
  * @supported weapp
@@ -95,11 +91,11 @@ declare namespace Taro {
95
91
 
96
92
  namespace UDPSocket {
97
93
  /** 关闭事件的回调函数 */
98
- type OffCloseCallback = (res: General.CallbackResult) => void
94
+ type OffCloseCallback = (res: TaroGeneral.CallbackResult) => void
99
95
  /** 错误事件的回调函数 */
100
- type OffErrorCallback = (res: General.CallbackResult) => void
96
+ type OffErrorCallback = (res: TaroGeneral.CallbackResult) => void
101
97
  /** 关闭事件的回调函数 */
102
- type OnCloseCallback = (res: General.CallbackResult) => void
98
+ type OnCloseCallback = (res: TaroGeneral.CallbackResult) => void
103
99
  /** 错误事件的回调函数 */
104
100
  type OnErrorCallback = (
105
101
  result: OnErrorCallbackResult,
@@ -108,7 +104,7 @@ declare namespace Taro {
108
104
  type OnMessageCallback = (
109
105
  result: OnMessageCallbackResult,
110
106
  ) => void
111
- interface OnErrorCallbackResult extends General.CallbackResult {
107
+ interface OnErrorCallbackResult extends TaroGeneral.CallbackResult {
112
108
  /** 错误信息 */
113
109
  errMsg: string
114
110
  }
@@ -133,11 +129,19 @@ declare namespace Taro {
133
129
  /** 需要发送的内容 */
134
130
  data: string | ArrayBuffer
135
131
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
136
- complete?: (res: General.CallbackResult) => void
132
+ complete?: (res: TaroGeneral.CallbackResult) => void
137
133
  /** 接口调用失败的回调函数 */
138
- fail?: (res: General.CallbackResult) => void
134
+ fail?: (res: TaroGeneral.CallbackResult) => void
139
135
  /** 接口调用成功的回调函数 */
140
- success?: (res: General.CallbackResult) => void
136
+ success?: (res: TaroGeneral.CallbackResult) => void
141
137
  }
142
138
  }
139
+
140
+ interface TaroStatic {
141
+ /** 创建一个 UDP Socket 实例。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
142
+ * @supported weapp
143
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/wx.createUDPSocket.html
144
+ */
145
+ createUDPSocket(): UDPSocket
146
+ }
143
147
  }