diff --git a/packages/taro/types/api/cloud/index.d.ts b/packages/taro/types/api/cloud/index.d.ts index d76398d5f56d..ad7b165323ca 100644 --- a/packages/taro/types/api/cloud/index.d.ts +++ b/packages/taro/types/api/cloud/index.d.ts @@ -239,7 +239,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/functions/Cloud.callFunction.html */ - static callFunction(param: cloud.CallFunctionParam): Promise | void + static callFunction(param: OQ): void + static callFunction(param: RQ): Promise /** 将本地资源上传至云存储空间,如果上传至同一路径则是覆盖写 * @supported weapp @@ -271,7 +272,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/uploadFile/client.uploadFile.html */ - static uploadFile(param: cloud.UploadFileParam): Promise | Taro.UploadTask + static uploadFile(param: OQ): Taro.UploadTask + static uploadFile(param: RQ): Promise /** 从云存储空间下载文件 * @supported weapp @@ -301,9 +303,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/downloadFile/client.downloadFile.html */ - static downloadFile( - param: cloud.DownloadFileParam, - ): Promise | Taro.DownloadTask + static downloadFile(param: OQ): Taro.DownloadTask + static downloadFile(param: RQ): Promise /** 用云文件 ID 换取真实链接,公有读的文件获取的链接不会过期,私有的文件获取的链接十分钟有效期。一次最多取 50 个。 * @supported weapp @@ -336,7 +337,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/Cloud.getTempFileURL.html */ - static getTempFileURL(param: cloud.GetTempFileURLParam): Promise | void + static getTempFileURL(param: OQ): void + static getTempFileURL(param: RQ): Promise /** 从云存储空间删除文件,一次最多 50 个 * @supported weapp @@ -369,7 +371,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/Cloud.deleteFile.html */ - static deleteFile(param: cloud.DeleteFileParam): Promise | void + static deleteFile(param: OQ): void + static deleteFile(param: RQ): Promise /** 获取数据库实例 * @supported weapp @@ -763,10 +766,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.add.html */ - add( - /** 新增记录的定义 */ - options: Document.IAddDocumentOptions - ): Promise | void + add(options: OQ): void + add(options: RQ): Promise /** 监听集合中符合查询条件的数据的更新事件。注意使用 watch 时,只有 where 语句会生效,orderBy、limit 等不生效。 * @supported weapp @@ -849,7 +850,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.get.html */ - get(options: Document.IGetDocumentOptions): Promise | void + get(options: OQ): void + get(options: RQ): Promise /** 替换更新一条记 * @supported weapp @@ -903,7 +905,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.set.html */ - set(options: Document.ISetSingleDocumentOptions): Promise | void + set(options: OQ): void + set(options: RQ): Promise /** 更新一条记录 * @supported weapp @@ -932,7 +935,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.update.html */ - update(options: Document.IUpdateSingleDocumentOptions): Promise | void + update(options: OQ): void + update(options: RQ): Promise /** 删除一条记录 * @supported weapp @@ -951,7 +955,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.remove.html */ - remove(options: Document.IRemoveSingleDocumentOptions): Promise | void + remove(options: OQ): void + remove(options: RQ): Promise } namespace Document { @@ -1261,7 +1266,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.get.html */ - get(options: Document.IGetDocumentOptions): Promise | void + get(options: OQ): void + get(options: RQ): Promise /** 统计匹配查询条件的记录的条数 * @supported weapp @@ -1288,7 +1294,8 @@ declare namespace Taro { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.count.html */ - count(options: Document.ICountDocumentOptions): Promise | void + count(options: OQ): void + count(options: RQ): Promise } namespace Query { @@ -2272,3 +2279,24 @@ declare namespace Taro { } } } + +type Optional = { [K in keyof T]+?: T[K] } + +type OQ< + T extends Optional< + Record<'complete' | 'success' | 'fail', (...args: any[]) => any> + > +> = + | (RQ & Required>) + | (RQ & Required>) + | (RQ & Required>) + | (RQ & Required>) + | (RQ & Required>) + | (RQ & Required>) + | (RQ & Required>) + +type RQ< + T extends Optional< + Record<'complete' | 'success' | 'fail', (...args: any[]) => any> + > +> = Pick> \ No newline at end of file