Skip to content

Commit

Permalink
chore(type): useShareAppMessage 类型定义增强 (#13303)
Browse files Browse the repository at this point in the history
* chore(type): useShareAppMessage 类型定义支持传入异步函数

* feat(type): useShareAppMessage 返回对象中支持 'promise' 属性

* fix(types): 优化分享生命周期类型

---------

Co-authored-by: Zakary <zakarycode@gmail.com>
  • Loading branch information
bigmeow and ZakaryCode authored Mar 3, 2023
1 parent fddcd66 commit 17b1488
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions packages/taro/types/taro.lifecycle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,19 @@ declare module './index' {
* 转发事件来源
* `button`:页面内转发按钮
* `menu`:右上角转发菜单
*
* @since 1.2.4
*/
from?: 'button' | 'menu' | string
/**
* 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
*
* @since 1.2.4
*/
target?: object
/**
* 页面中包含 `<web-view>` 组件时,返回当前 `<web-view>` 的 url
*
* @since 1.6.4
*/
webViewUrl?: string
}

interface ShareAppMessageReturn {
interface ShareAppMessageReturnObject {
/**
* 转发标题,默认为当前小程序名称
*/
Expand All @@ -101,12 +95,44 @@ declare module './index' {
* 支持PNG及JPG
* 显示图片长宽比是 5:4
* 默认使用截图
*
* @since 1.5.0
*/
imageUrl?: string
}

interface WeappShareAppMessageReturnObject extends ShareAppMessageReturnObject {
/**
* 如果该参数存在,则以 resolve 结果为准,如果三秒内不 resolve,分享会使用上面传入的默认参数
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareAppMessage-Object-object
* @example
* ```tsx
* import { ShareAppMessageReturnObject, useShareAppMessage } from "@tarojs/taro";
* // ... else code
* useShareAppMessage(() => {
* const p = new Promise<ShareAppMessageReturnObject>(resolve => {
* setTimeout(() => {
* resolve({
* title: "",
* imageUrl: "",
* path: ""
* })
* }, 2000)
* })
* return {
* title: "",
* imageUrl: "",
* path: "",
* promise: p
* }
* });
* ```
*
*/
promise: Promise<ShareAppMessageReturnObject>
}

type ShareAppMessageReturn = ShareAppMessageReturnObject | Promise<ShareAppMessageReturnObject> | WeappShareAppMessageReturnObject

interface TabItemTapObject {
/**
* 被点击tabItem的序号,从 0 开始
Expand Down

0 comments on commit 17b1488

Please sign in to comment.