Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否把uni声明文件中的返回void改为返回promise #2556

Closed
alamhubb opened this issue Mar 26, 2021 · 3 comments
Closed

能否把uni声明文件中的返回void改为返回promise #2556

alamhubb opened this issue Mar 26, 2021 · 3 comments

Comments

@alamhubb
Copy link

文档中说了,很多返回的都说promise,可是.d.ts文件中还写的 void

uni-app 对部分 API 进行了 Promise 封装,返回数据的第一个参数是错误对象,第二个参数是返回数据。

详细策略如下:

异步的方法,如果不传入 success、fail、complete 等 callback 参数,将以 Promise 返回数据。例如:uni.getImageInfo()
异步的方法且有返回对象,如果希望获取返回对象,必须至少传入一项 success、fail、complete 等 callback 参数。例如:uni.connectSocket()
同步的方法(即以 sync 结束),不封装 Promise。例如:uni.getSystemInfoSync()
以 create 开头的方法,不封装 Promise。例如:uni.createMapContext()
以 manager 结束的方法,不封装 Promise。例如:uni.getBackgroundAudioManager()

@StrivingRabbit
Copy link
Collaborator

@StrivingRabbit
Copy link
Collaborator

StrivingRabbit commented Feb 13, 2023

关于api 的 Promise 化类型提示。除 uni.request 有返回值同步的方法(即以 sync 结束)以 create 开头的方法以 manager 结束的方法返回 task 的 api 暂不处理外,其他可以升级 @dcloudio/[email protected] 试试看

@StrivingRabbit
Copy link
Collaborator

部分 api promise 化提示已支持,后续进度请跟踪 #3009 查看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants