@tarojs/taro 3.5.0-alpha.13 → 3.5.0-alpha.16

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 (64) hide show
  1. package/index.js +3 -4
  2. package/package.json +7 -9
  3. package/types/api/base/debug.d.ts +1 -1
  4. package/types/api/base/index.d.ts +3 -3
  5. package/types/api/base/performance.d.ts +5 -5
  6. package/types/api/base/system.d.ts +2 -2
  7. package/types/api/base/update.d.ts +6 -6
  8. package/types/api/base/weapp/app-event.d.ts +56 -17
  9. package/types/api/base/weapp/life-cycle.d.ts +7 -7
  10. package/types/api/canvas/index.d.ts +1 -1
  11. package/types/api/data-analysis/index.d.ts +1 -1
  12. package/types/api/device/accelerometer.d.ts +3 -3
  13. package/types/api/device/calendar.d.ts +1 -1
  14. package/types/api/device/clipboard.d.ts +2 -2
  15. package/types/api/device/compass.d.ts +3 -3
  16. package/types/api/device/gyroscope.d.ts +4 -4
  17. package/types/api/device/keyboard.d.ts +1 -1
  18. package/types/api/device/memory.d.ts +1 -1
  19. package/types/api/device/network.d.ts +2 -2
  20. package/types/api/device/phone.d.ts +1 -1
  21. package/types/api/device/scan.d.ts +1 -1
  22. package/types/api/device/screen.d.ts +5 -5
  23. package/types/api/device/vibrate.d.ts +6 -2
  24. package/types/api/device/wifi.d.ts +3 -3
  25. package/types/api/ext/index.d.ts +2 -2
  26. package/types/api/files/index.d.ts +32 -32
  27. package/types/api/framework/index.d.ts +5 -4
  28. package/types/api/location/index.d.ts +45 -9
  29. package/types/api/media/audio.d.ts +1 -1
  30. package/types/api/media/background-audio.d.ts +1 -1
  31. package/types/api/media/camera.d.ts +8 -8
  32. package/types/api/media/image.d.ts +5 -5
  33. package/types/api/media/map.d.ts +15 -15
  34. package/types/api/media/recorder.d.ts +9 -9
  35. package/types/api/media/video.d.ts +2 -2
  36. package/types/api/navigate/index.d.ts +2 -2
  37. package/types/api/network/download.d.ts +27 -8
  38. package/types/api/network/request.d.ts +3 -3
  39. package/types/api/network/upload.d.ts +19 -8
  40. package/types/api/network/websocket.d.ts +6 -6
  41. package/types/api/open-api/address.d.ts +1 -1
  42. package/types/api/open-api/authorize.d.ts +1 -1
  43. package/types/api/open-api/settings.d.ts +2 -2
  44. package/types/api/open-api/subscribe-message.d.ts +2 -2
  45. package/types/api/open-api/user-info.d.ts +2 -2
  46. package/types/api/route/index.d.ts +5 -5
  47. package/types/api/share/index.d.ts +2 -2
  48. package/types/api/storage/index.d.ts +10 -10
  49. package/types/api/ui/animation.d.ts +34 -36
  50. package/types/api/ui/interaction.d.ts +6 -6
  51. package/types/api/ui/menu.d.ts +1 -1
  52. package/types/api/ui/navigation-bar.d.ts +5 -5
  53. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  54. package/types/api/ui/scroll.d.ts +4 -2
  55. package/types/api/ui/tab-bar.d.ts +8 -8
  56. package/types/api/wxml/index.d.ts +16 -16
  57. package/types/compile.d.ts +18 -4
  58. package/types/global.d.ts +1 -1
  59. package/types/taro.component.d.ts +12 -63
  60. package/types/taro.config.d.ts +29 -0
  61. package/types/taro.extend.d.ts +24 -20
  62. package/types/taro.hooks.d.ts +55 -3
  63. package/types/taro.lifecycle.d.ts +21 -14
  64. package/LICENSE +0 -21
@@ -18,12 +18,12 @@ declare module '../../index' {
18
18
  */
19
19
  interface IntersectionObserver {
20
20
  /** 停止监听。回调函数将不再触发
21
- * @supported weapp
21
+ * @supported weapp, tt
22
22
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/IntersectionObserver.disconnect.html
23
23
  */
24
24
  disconnect(): void
25
25
  /** 指定目标节点并开始监听相交状态变化情况
26
- * @supported weapp
26
+ * @supported weapp, tt
27
27
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/IntersectionObserver.observe.html
28
28
  */
29
29
  observe(
@@ -33,7 +33,7 @@ declare module '../../index' {
33
33
  callback: IntersectionObserver.ObserveCallback,
34
34
  ): void
35
35
  /** 使用选择器指定一个节点,作为参照区域之一。
36
- * @supported weapp
36
+ * @supported weapp, tt
37
37
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/IntersectionObserver.relativeTo.html
38
38
  */
39
39
  relativeTo(
@@ -43,7 +43,7 @@ declare module '../../index' {
43
43
  margins?: IntersectionObserver.RelativeToMargins,
44
44
  ): IntersectionObserver
45
45
  /** 指定页面显示区域作为参照区域之一
46
- * @supported weapp
46
+ * @supported weapp, tt
47
47
  * @example
48
48
  * 下面的示例代码中,如果目标节点(用选择器 .target-class 指定)进入显示区域以下 100px 时,就会触发回调函数。
49
49
  *
@@ -184,7 +184,7 @@ declare module '../../index' {
184
184
  */
185
185
  interface NodesRef {
186
186
  /** 添加节点的布局位置的查询请求。相对于显示区域,以像素为单位。其功能类似于 DOM 的 `getBoundingClientRect`。返回 `NodesRef` 对应的 `SelectorQuery`。
187
- * @supported weapp, h5
187
+ * @supported weapp, h5, tt
188
188
  * @example
189
189
  * ```tsx
190
190
  * Taro.createSelectorQuery().select('#the-id').boundingClientRect(function(rect){
@@ -220,7 +220,7 @@ declare module '../../index' {
220
220
  callback?: NodesRef.BoundingClientRectCallback,
221
221
  ): SelectorQuery
222
222
  /** 添加节点的 Context 对象查询请求。目前支持 [VideoContext](/docs/apis/media/video/VideoContext)、[CanvasContext](/docs/apis/canvas/CanvasContext)、[LivePlayerContext](/docs/apis/media/live/LivePlayerContext)、[EditorContext](/docs/apis/media/editor/EditorContext)和 [MapContext](/docs/apis/media/map/MapContext) 的获取。
223
- * @supported weapp, h5
223
+ * @supported weapp, h5, tt
224
224
  * @example
225
225
  * ```tsx
226
226
  * Taro.createSelectorQuery().select('.the-video-class').context(function (res) {
@@ -237,7 +237,7 @@ declare module '../../index' {
237
237
  *
238
238
  * **注意**
239
239
  * computedStyle 的优先级高于 size,当同时在 computedStyle 里指定了 width/height 和传入了 size: true,则优先返回 computedStyle 获取到的 width/height。
240
- * @supported weapp, h5
240
+ * @supported weapp, h5, tt
241
241
  * @example
242
242
  * ```tsx
243
243
  * Taro.createSelectorQuery().select('#the-id').fields({
@@ -269,7 +269,7 @@ declare module '../../index' {
269
269
  callback?: NodesRef.FieldsCallback,
270
270
  ): SelectorQuery
271
271
  /** 获取 Node 节点实例。目前支持 [Canvas](/docs/components/canvas) 的获取。
272
- * @supported weapp, h5
272
+ * @supported weapp, h5, tt
273
273
  * @example
274
274
  * ```tsx
275
275
  * Taro.createSelectorQuery().select('.canvas').node(function(res){
@@ -283,7 +283,7 @@ declare module '../../index' {
283
283
  callback?: NodesRef.NodeCallback,
284
284
  ): SelectorQuery
285
285
  /** 添加节点的滚动位置查询请求。以像素为单位。节点必须是 `scroll-view` 或者 `viewport`,返回 `NodesRef` 对应的 `SelectorQuery`。
286
- * @supported weapp, h5
286
+ * @supported weapp, h5, tt
287
287
  * @example
288
288
  * ```tsx
289
289
  * Taro.createSelectorQuery().selectViewport().scrollOffset(function(res){
@@ -384,7 +384,7 @@ declare module '../../index' {
384
384
  */
385
385
  interface SelectorQuery {
386
386
  /** 执行所有的请求。请求结果按请求次序构成数组,在callback的第一个参数中返回。
387
- * @supported weapp, h5
387
+ * @supported weapp, h5, tt
388
388
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/SelectorQuery.exec.html
389
389
  */
390
390
  exec(
@@ -392,7 +392,7 @@ declare module '../../index' {
392
392
  callback?: (...args: any[]) => any,
393
393
  ): NodesRef
394
394
  /** 将选择器的选取范围更改为自定义组件 `component` 内。(初始时,选择器仅选取页面范围的节点,不会选取任何自定义组件中的节点)。
395
- * @supported weapp, h5
395
+ * @supported weapp, h5, tt
396
396
  * @example
397
397
  * ```tsx
398
398
  * Component({
@@ -423,7 +423,7 @@ declare module '../../index' {
423
423
  * - 后代选择器:.the-ancestor .the-descendant
424
424
  * - 跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
425
425
  * - 多选择器的并集:#a-node, .some-other-nodes
426
- * @supported weapp, h5
426
+ * @supported weapp, h5, tt
427
427
  * @example
428
428
  * ```tsx
429
429
  * Taro.createSelectorQuery().select('#the-id').fields({
@@ -459,7 +459,7 @@ declare module '../../index' {
459
459
  * - 后代选择器:.the-ancestor .the-descendant
460
460
  * - 跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
461
461
  * - 多选择器的并集:#a-node, .some-other-nodes
462
- * @supported weapp, h5
462
+ * @supported weapp, h5, tt
463
463
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/SelectorQuery.selectAll.html
464
464
  */
465
465
  selectAll(
@@ -467,7 +467,7 @@ declare module '../../index' {
467
467
  selector: string,
468
468
  ): NodesRef
469
469
  /** 选择显示区域。可用于获取显示区域的尺寸、滚动位置等信息。
470
- * @supported weapp, h5
470
+ * @supported weapp, h5, tt
471
471
  * @example
472
472
  * ```tsx
473
473
  * Taro.createSelectorQuery().selectViewport().scrollOffset(function (res) {
@@ -484,7 +484,7 @@ declare module '../../index' {
484
484
 
485
485
  interface TaroStatic {
486
486
  /** 返回一个 SelectorQuery 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createSelectorQuery()` 来代替。
487
- * @supported weapp, h5
487
+ * @supported weapp, h5, tt
488
488
  * @example
489
489
  * ```tsx
490
490
  * const query = Taro.createSelectorQuery()
@@ -500,7 +500,7 @@ declare module '../../index' {
500
500
  createSelectorQuery(): SelectorQuery
501
501
 
502
502
  /** 创建并返回一个 IntersectionObserver 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createIntersectionObserver([options])` 来代替。
503
- * @supported weapp
503
+ * @supported weapp, tt
504
504
  * @example
505
505
  * ```tsx
506
506
  * const observer = Taro.createIntersectionObserver(this, { thresholds: [0], observeAll: true })
@@ -1,6 +1,8 @@
1
+ import swc from '@swc/core'
1
2
  export { Current } from '@tarojs/runtime'
2
3
  import webpack from 'webpack'
3
4
  import webpackDevServer from 'webpack-dev-server'
5
+ import HtmlWebpackPlugin from 'html-webpack-plugin'
4
6
 
5
7
  export const enum TEMPLATE_TYPES {
6
8
  WEAPP = '.wxml',
@@ -119,7 +121,6 @@ interface Runtime {
119
121
 
120
122
  export interface IMiniAppConfig {
121
123
  appOutput?: boolean
122
- enableSourceMap?: boolean
123
124
  sourceMapType?: string
124
125
  debugReact?: boolean
125
126
  minifyXML?: {
@@ -127,7 +128,6 @@ export interface IMiniAppConfig {
127
128
  }
128
129
 
129
130
  webpackChain?: (chain: any, webpack: any, PARSE_AST_TYPE: any) => void
130
- entry?: webpack.EntryObject
131
131
  output?: webpack.Output
132
132
  postcss?: IPostcssOption
133
133
  cssLoaderOption?: IOption
@@ -177,11 +177,9 @@ export interface IH5Config {
177
177
 
178
178
  webpackChain?: (chain: any, webpack: any) => void
179
179
 
180
- entry?: webpack.EntryObject
181
180
  output?: webpack.Output
182
181
  router?: IH5RouterConfig
183
182
  devServer?: webpackDevServer.Configuration
184
- enableSourceMap?: boolean
185
183
  sourceMapType?: 'none' | 'eval' | 'cheap-eval-source-map' | 'cheap-module-eval-source-map' | 'eval-source-map' | 'cheap-source-map' | 'cheap-module-source-map' | 'inline-cheap-source-map' | 'inline-cheap-module-source-map' | 'source-map' | 'inline-source-map' | 'hidden-source-map' | 'nosources-source-map'
186
184
  enableExtract?: boolean
187
185
  transformOnly?: boolean
@@ -199,6 +197,7 @@ export interface IH5Config {
199
197
  useHtmlComponents?: boolean
200
198
 
201
199
  postcss?: IPostcssOption
200
+ htmlPluginOption?: HtmlWebpackPlugin.Options
202
201
  }
203
202
 
204
203
  type FeatureItem = {
@@ -371,6 +370,11 @@ interface IPrebundle {
371
370
  force?: boolean
372
371
  include?: string[]
373
372
  exclude?: string[]
373
+ esbuild?: Record<string, any>
374
+ swc?: swc.Config
375
+ webpack?: {
376
+ provide?: any[]
377
+ }
374
378
  }
375
379
  interface ICompiler {
376
380
  type: CompilerTypes
@@ -384,6 +388,8 @@ interface ILogger {
384
388
  }
385
389
 
386
390
  export interface IProjectBaseConfig {
391
+ isWatch?: boolean
392
+ port?: number
387
393
  projectName?: string
388
394
  date?: string
389
395
  designWidth?: number
@@ -406,9 +412,17 @@ export interface IProjectBaseConfig {
406
412
  presets?: PluginItem[]
407
413
  baseLevel?: number
408
414
  framework?: string
415
+ frameworkExts?: string[]
409
416
  compiler?: Compiler
410
417
  cache?: ICache
411
418
  logger?: ILogger
419
+ enableSourceMap?: boolean
420
+ /** hooks */
421
+ modifyWebpackChain?: HookModifyWebpackChain
422
+ modifyMiniConfigs?: (configMap) => Promise<any>
423
+ modifyBuildAssets?: (assets, plugin?) => Promise<any>
424
+ onWebpackChainReady?: (webpackChain: Chain) => Promise<any>
425
+ onBuildFinish?: (res: { error, stats, isWatch }) => Promise<any>
412
426
  }
413
427
 
414
428
  export interface IProjectConfig extends IProjectBaseConfig {
package/types/global.d.ts CHANGED
@@ -215,7 +215,7 @@ declare namespace TaroGeneral {
215
215
  * @illustrate 正常
216
216
  */
217
217
  0
218
- /** unsupport
218
+ /** nonsupport
219
219
  * @illustrate 系统或设备不支持
220
220
  */
221
221
  11000
@@ -4,35 +4,6 @@ import Vue from 'vue'
4
4
  import Taro, { Config } from './index'
5
5
 
6
6
  declare module './index' {
7
- // Components
8
- interface ComponentLifecycle<P, S, SS = any> extends NewLifecycle<P, S, SS> {
9
- componentWillMount?(): void
10
- componentDidMount?(): void
11
- componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void
12
- shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean
13
- componentWillUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void
14
- componentWillUnmount?(): void
15
- componentDidShow?(): void
16
- componentDidHide?(): void
17
- componentDidCatchError?(err: string): void
18
- componentDidNotFound?(obj: PageNotFoundObject): void
19
- onPullDownRefresh?(): void
20
- onReachBottom?(): void
21
- onPageScroll?(obj: PageScrollObject): void
22
- onShareAppMessage?(obj: ShareAppMessageObject): ShareAppMessageReturn
23
- onTabItemTap?(obj: TabItemTapObject): void
24
- onResize?(obj: PageResizeObject): void
25
- }
26
- interface ComponentOptions {
27
- addGlobalClass?: boolean
28
- styleIsolation?: 'isolated' | 'apply-shared' | 'shared'
29
- }
30
- interface ComponentClass<P = {}, S = any> extends StaticLifecycle<P, S> {
31
- new (...args: any[]): Component<P, {}>
32
- propTypes?: any // TODO: Use prop-types type definition.
33
- defaultProps?: Partial<P>
34
- displayName?: string
35
- }
36
7
  // ref: packages/taro-runtime/src/current.ts
37
8
  interface RouterInfo<TParams extends Partial<Record<string, string>> = Partial<Record<string, string>>> {
38
9
  /** 路由参数 */
@@ -47,24 +18,8 @@ declare module './index' {
47
18
 
48
19
  shareTicket: string | undefined
49
20
  scene: number | undefined
21
+ exitState?: any
50
22
  }
51
- interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {
52
- $scope?: any
53
- }
54
- type PropsWithChildren<P> = P & { children?: React.ReactNode }
55
- interface FunctionComponent<P = {}> {
56
- (props: PropsWithChildren<P>, context?: any): React.ReactElement | null
57
- propTypes?: any // TODO: Use prop-types type definition.
58
- defaultProps?: Partial<P>
59
- config?: Config
60
- options?: ComponentOptions
61
- externalClasses?: string[]
62
- }
63
- type FC<P = {}> = FunctionComponent<P>
64
- interface StatelessFunctionComponent {
65
- (): JSX.Element
66
- }
67
- type SFC = StatelessFunctionComponent
68
23
 
69
24
  interface Show {
70
25
  componentDidShow?(): void
@@ -73,10 +28,10 @@ declare module './index' {
73
28
  onHide?(): void
74
29
  }
75
30
  interface AppInstance extends Show {
76
- mount(component: React.Component | Vue.ComponentOptions<Vue>, id: string, cb: () => void): void
31
+ mount(component: React.Component | Vue.ComponentOptions<Vue>, id: string, cb: (...args: any[]) => void): void
77
32
  componentDidShow?(options?: Record<string, unknown>): void
78
33
  onShow?(options?: Record<string, unknown>): void
79
- unmount(id: string, cb: () => void): void
34
+ unmount(id: string, cb?: () => void): void
80
35
  }
81
36
  type Target = Record<string, unknown> & { dataset: Record<string, unknown>; id: string }
82
37
  interface MpEvent {
@@ -86,18 +41,18 @@ declare module './index' {
86
41
  currentTarget: Target
87
42
  }
88
43
  interface PageLifeCycle extends Show {
89
- onPullDownRefresh?(): void
90
- onReachBottom?(): void
91
- onPageScroll?(obj: { scrollTop: number }): void
92
- onShareAppMessage?(obj: { from: string; target?: any; webViewUrl: string }): void
93
- onResize?(options: unknown): void
94
- onTabItemTap?(obj: { index: string; pagePath: string; text: string }): void
95
- onTitleClick?(): void
44
+ eh?(event: MpEvent): void
45
+ onLoad(options: Record<string, unknown>): void
96
46
  onOptionMenuClick?(): void
47
+ onPageScroll?(opt: PageScrollObject): void
97
48
  onPopMenuClick?(): void
49
+ onPullDownRefresh?(): void
98
50
  onPullIntercept?(): void
99
- eh?(event: MpEvent): void
100
- onLoad(options: Record<string, unknown>): void
51
+ onReachBottom?(): void
52
+ onResize?(opt: PageResizeObject): void
53
+ onShareAppMessage?(opt: ShareAppMessageObject): ShareAppMessageReturn
54
+ onTabItemTap?(opt: TabItemTapObject): void
55
+ onTitleClick?(): void
101
56
  onUnload(): void
102
57
  }
103
58
  interface ComponentInstance<
@@ -184,10 +139,4 @@ declare module './index' {
184
139
  /** 页面的组件选项 */
185
140
  options?: Record<string, unknown>
186
141
  }
187
- interface TaroStatic {
188
- memo<P = {}>(
189
- FunctionComponent: FunctionComponent<P>,
190
- compare?: (oldProps: P, newProps: P) => boolean
191
- ): FunctionComponent<P>
192
- }
193
142
  }
@@ -271,6 +271,19 @@ declare module './index' {
271
271
  * @since 微信客户端 6.7.2 及以上版本支持
272
272
  */
273
273
  requiredBackgroundModes?: ('audio' | 'location')[]
274
+ /** 申明需要使用的地理位置相关接口,类型为数组。目前支持以下项目:
275
+ * 自 2022 年 7 月 14 日后发布的小程序,使用以下8个地理位置相关接口时,需要声明该字段,否则将无法正常使用。2022 年 7 月 14 日前发布的小程序不受影响。
276
+ * - getFuzzyLocation: 获取模糊地理位置
277
+ * - getLocation: 获取精确地理位置
278
+ * - onLocationChange: 监听试试地理位置变化事件
279
+ * - startLocationUpdate: 接收位置消息(前台)
280
+ * - startLocationUpdateBackground: 接收位置消息(前后台)
281
+ * - chooseLocation: 打开地图选择位置
282
+ * - choosePoi: 打开 POI 列表选择位置
283
+ * - chooseAddress: 获取用户地址信息
284
+ * @see https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#requiredPrivateInfos
285
+ */
286
+ requiredPrivateInfos?: ('getFuzzyLocation' | 'getLocation' | 'onLocationChange' | 'startLocationUpdate' | 'startLocationUpdateBackground' | 'chooseLocation' | 'choosePoi' | 'chooseAddress')[]
274
287
  /** 使用到的插件
275
288
  * @since 1.9.6
276
289
  */
@@ -359,6 +372,22 @@ declare module './index' {
359
372
  /** 视频号直播打开的第一个页面的全屏状态使用自定义顶部,支持 */
360
373
  firstPageNavigationStyle?: 'default' | 'custom'
361
374
  }
375
+ /** 小程序调试相关配置项 */
376
+ debugOptions?: {
377
+ /** 是否开启 FPS 面板,默认false */
378
+ enableFPSPanel?: boolean
379
+ }
380
+ /** touch 事件监听是否为 passive,默认false */
381
+ enablePassiveEvent?: boolean | {
382
+ /** 是否设置 touchstart 事件为 passive,默认false */
383
+ touchstart?: boolean
384
+ /** 是否设置 touchmove 事件为 passive,默认false */
385
+ touchmove?: boolean
386
+ /** 是否设置 wheel 事件为 passive,默认false */
387
+ wheel?: boolean
388
+ }
389
+ /** 自定义模块映射规则 */
390
+ resolveAlias?: Record<string, string>
362
391
  /** 接受一个数组,每一项都是字符串,来指定编译为原生小程序组件的组件入口 */
363
392
  components?: string[]
364
393
  /** 渲染页面的容器 id
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
 
3
- import Taro, { Component } from './index'
3
+ import Taro from './index'
4
4
 
5
5
  declare module './index' {
6
6
  type MessageType = 'info' | 'success' | 'error' | 'warning'
@@ -11,7 +11,7 @@ declare module './index' {
11
11
  duration?: number
12
12
  }
13
13
 
14
- interface RequestParams<T> extends request.Option<T, any> {
14
+ interface RequestParams<T=any> extends request.Option<T, any> {
15
15
  [propName: string]: any
16
16
  }
17
17
 
@@ -49,36 +49,41 @@ declare module './index' {
49
49
  new (): TaroGeneral.Events
50
50
  }
51
51
 
52
- // eventCenter
52
+ /** 事件中心
53
+ * @supported global
54
+ */
53
55
  eventCenter: TaroGeneral.Events
54
56
 
55
57
  ENV_TYPE: TARO_ENV_TYPE
56
58
 
59
+ /** 获取环境变量
60
+ * @supported global
61
+ */
57
62
  getEnv(): TaroGeneral.ENV_TYPE
58
63
 
59
- render(component: Component | JSX.Element, element: Element | null): any
60
-
61
- internal_safe_set(...arg: any[]): any
62
- internal_safe_get(...arg: any[]): any
63
-
64
- atMessage(options: AtMessageOptions): void
65
-
64
+ /** 尺寸转换
65
+ * @supported global
66
+ */
66
67
  pxTransform(size: number, designWidth?: number): string
68
+
69
+ /** 尺寸转换初始化
70
+ * @supported global
71
+ */
67
72
  initPxTransform(config: { designWidth: number; deviceRatio: TaroGeneral.TDeviceRatio }): void
68
73
 
69
- /**
70
- * 小程序引用插件 JS 接口
74
+ /** 小程序引用插件 JS 接口
75
+ * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
71
76
  */
72
77
  requirePlugin(pluginName: string): any
73
78
 
74
- setIsUsingDiff (flag: boolean)
75
-
76
- Current: Current
77
-
79
+ /** 获取当前页面实例
80
+ * @supported global
81
+ */
78
82
  getCurrentInstance(): Current
83
+ Current: Current
79
84
 
80
- /**
81
- * @desc Vue3 插件,用于设置 `getApp()` 中的全局变量
85
+ /** Vue3 插件,用于设置 `getApp()` 中的全局变量
86
+ * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
82
87
  * @example
83
88
  * ```js
84
89
  * // 使用插件
@@ -92,9 +97,8 @@ declare module './index' {
92
97
  */
93
98
  setGlobalDataPlugin: SetGlobalDataPlugin
94
99
 
95
- /**
100
+ /** 获取自定义 TabBar 对应的 React 或 Vue 组件实例
96
101
  * @supported weapp
97
- * @desc 获取自定义 TabBar 对应的 React 或 Vue 组件实例
98
102
  * @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取
99
103
  */
100
104
  getTabBar<T>(page: Current['page']): T | undefined
@@ -4,80 +4,132 @@ declare module './index' {
4
4
  interface TaroStatic {
5
5
  /**
6
6
  * 页面展示时的回调。
7
+ * @supported global
7
8
  */
8
9
  useDidShow(callback: () => void): void
9
10
 
10
11
  /**
11
12
  * 页面隐藏时的回调。
13
+ * @supported global
12
14
  */
13
15
  useDidHide(callback: () => void): void
14
16
 
15
17
  /**
16
18
  * 下拉刷新时的回调。
19
+ * @supported global
17
20
  */
18
21
  usePullDownRefresh(callback: () => void): void
19
22
 
20
23
  /**
21
24
  * 上拉触底时的回调。
25
+ * @supported global
22
26
  */
23
27
  useReachBottom(callback: () => void): void
24
28
 
25
29
  /**
26
30
  * 页面滚动时的回调。
31
+ * @supported global
27
32
  */
28
33
  usePageScroll(callback: (payload: PageScrollObject) => void): void
29
34
 
30
35
  /**
31
36
  * 页面尺寸改变时的回调。
37
+ * @supported global
32
38
  */
33
39
  useResize(callback: (payload: PageResizeObject) => void): void
34
40
 
35
41
  /**
36
42
  * 页面转发时的回调。
43
+ * @supported weapp
37
44
  */
38
45
  useShareAppMessage(callback: (payload: ShareAppMessageObject) => ShareAppMessageReturn): void
39
46
 
40
47
  /**
41
48
  * 当前是 tab 页时,tab 被点击时的回调。
49
+ * @supported weapp, rn
42
50
  */
43
51
  useTabItemTap(callback: (payload: TabItemTapObject) => void): void
44
52
 
45
53
  /**
46
54
  * 用户点击右上角菜单“收藏”按钮时的回调。
55
+ * @supported weapp
47
56
  */
48
57
  useAddToFavorites(callback: (payload: AddToFavoritesObject) => AddToFavoritesReturnObject): void
49
58
 
50
59
  /**
51
60
  * 用户点击右上角菜单“分享到朋友圈”按钮时的回调。
61
+ * @supported weapp
52
62
  */
53
63
  useShareTimeline(callback: () => ShareTimelineReturnObject): void
54
64
 
65
+ /**
66
+ * 页面销毁前保留状态回调
67
+ * @supported weapp
68
+ */
69
+ useSaveExitState(callback: () => {
70
+ data: Record<any, any>
71
+ expireTimeStamp?: number
72
+ }): void
73
+
74
+ /**
75
+ * 小程序初始化完成时的回调。
76
+ * @supported weapp, h5
77
+ */
78
+ useLaunch(callback: (options: getLaunchOptionsSync.LaunchOptions) => void): void
79
+
80
+ /**
81
+ * 小程序发生脚本错误或 API 调用报错时触发的回调。
82
+ * @supported weapp, h5
83
+ */
84
+ useError(callback: (error: string) => void): void
85
+
86
+ /**
87
+ * 小程序要打开的页面不存在时触发的回调。
88
+ * @supported weapp, h5
89
+ * @h5 多页面模式不支持该方法
90
+ */
91
+ usePageNotFound(callback: (res: { path: string, query: Record<any, any>, isEntryPage: boolean, [key: string]: any }) => void): void
92
+
93
+ /**
94
+ * 页面加载完成时的回调。
95
+ * @supported weapp, h5
96
+ */
97
+ useLoad(callback: () => void): void
98
+
99
+ /**
100
+ * 页面卸载时的回调。
101
+ * @supported weapp, h5
102
+ */
103
+ useUnload(callback: () => void): void
104
+
55
105
  /**
56
106
  * 页面初次渲染完成的回调。
57
107
  * 此时页面已经准备妥当,可以和视图层进行交互。
108
+ * @supported weapp, h5
58
109
  */
59
110
  useReady(callback: () => void): void
60
111
 
61
112
  /**
62
113
  * 获取当前路由参数。
114
+ * @supported global
63
115
  */
64
116
  useRouter<TParams extends Partial<Record<string, string>> = Partial<Record<string, string>>>(dynamic?: boolean): RouterInfo<TParams>
65
117
 
66
118
  /**
67
119
  * 导航栏的标题被点击时的回调。
68
- * **仅支付宝小程序支持。**
120
+ * @supported alipay
69
121
  */
70
122
  useTitleClick(callback: () => void): void
71
123
 
72
124
  /**
73
125
  * 导航栏的额外图标被点击时的回调。
74
- * **仅支付宝小程序支持。**
126
+ * @supported alipay
75
127
  */
76
128
  useOptionMenuClick(callback: () => void): void
77
129
 
78
130
  /**
79
131
  * 下拉中断时的回调。
80
- * **仅支付宝小程序支持。**
132
+ * @supported alipay, h5
81
133
  */
82
134
  usePullIntercept(callback: () => void): void
83
135
  }
@@ -1,15 +1,15 @@
1
1
  import Taro from './index'
2
2
 
3
3
  type TaroGetDerivedStateFromProps<P, S> =
4
- /**
5
- * Returns an update to a component's state based on its new props and old state.
6
- *
7
- * Note: its presence prevents any of the deprecated lifecycle methods from being invoked
8
- */
9
- (nextProps: Readonly<P>, prevState: S) => Partial<S> | null;
4
+ /**
5
+ * Returns an update to a component's state based on its new props and old state.
6
+ *
7
+ * Note: its presence prevents any of the deprecated lifecycle methods from being invoked
8
+ */
9
+ (nextProps: Readonly<P>, prevState: S) => Partial<S> | null
10
10
 
11
11
  interface TaroStaticLifecycle<P, S> {
12
- getDerivedStateFromProps?: TaroGetDerivedStateFromProps<P, S>;
12
+ getDerivedStateFromProps?: TaroGetDerivedStateFromProps<P, S>
13
13
  }
14
14
 
15
15
  interface TaroNewLifecycle<P, S, SS> {
@@ -21,13 +21,13 @@ interface TaroNewLifecycle<P, S, SS> {
21
21
  * Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated
22
22
  * lifecycle events from running.
23
23
  */
24
- getSnapshotBeforeUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>): SS | null;
24
+ getSnapshotBeforeUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>): SS | null
25
25
  /**
26
26
  * Called immediately after updating occurs. Not called for the initial render.
27
27
  *
28
28
  * The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
29
29
  */
30
- componentDidUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS): void;
30
+ componentDidUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS): void
31
31
  }
32
32
 
33
33
  declare module './index' {
@@ -165,11 +165,18 @@ declare module './index' {
165
165
  imageUrl?: string
166
166
  }
167
167
 
168
- type GetDerivedStateFromProps<P, S> = TaroGetDerivedStateFromProps<P, S>
169
-
170
- type StaticLifecycle<P, S> = TaroStaticLifecycle<P, S>
171
-
172
- type NewLifecycle<P, S, SS> = TaroNewLifecycle<P, S, SS>
168
+ interface ComponentLifecycle<P, S, SS = any> extends TaroNewLifecycle<P, S, SS> {
169
+ componentWillMount?(): void
170
+ componentDidMount?(): void
171
+ componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void
172
+ shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean
173
+ componentWillUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void
174
+ componentWillUnmount?(): void
175
+ componentDidShow?(): void
176
+ componentDidHide?(): void
177
+ componentDidCatchError?(err: string): void
178
+ componentDidNotFound?(opt: PageNotFoundObject): void
179
+ }
173
180
 
174
181
  interface TaroStatic {
175
182
  PageNotFoundObject: PageNotFoundObject