-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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.d.ts不能正确推断类型 #1770
Comments
|
@zhetengbiji
2、目前这种返回参数是有点奇怪,建议错误在catch里抛出 |
这个request返回的类型是上次我给官方提议修改的,你不能为了自己偷懒就要求改成any 目前这个uni.d.ts里还有一些地方用的any,抽空我要找出来让官方一一改掉。滥用any不是好习惯。 |
@SiiZhao 原来是你提议的,那请教你两个问题? |
自己写上就好了,之前我提议的是string | object | ArrayBuffer,不过我看后来官方实现的是string | AnyObject | ArrayBuffer uni.request({
url,
success(res) {
const data = res.data;
console.log((<AnyObject>data).abc);
}
}); |
@SiiZhao 目前的定义有点画蛇添足,建议改成any。实际应用中返回数据都要和具体业务结合,比如返回一个订单对象,那就不是 |
没毛病啊 interface IOrder {
code: number
}
uni.request({
url,
success(res) {
const data = res.data;
console.log((<IOrder>data).code);
}
}); |
虽然我不赞成any,但是应该可以改的更智能。微信官方的typings也有类似提议,希望官方能参考一下: Should wx.request have a type parameter? |
@chejj 这种方式其实和消费data时再定义类型区别不大,data应该是什么类型是数据消费者定义的,场景千变万化,uniapp根本不可能预测,目前ts里只有any能覆盖所有可能,这也是为什么大部分框架都不会对接口返回数据去做约束。 |
似乎Uni官方的Promise响应不大一样,还得改改就好 |
关于api 的 Promise 化类型提示。除 |
部分 api promise 化提示已支持,后续进度请跟踪 #3009 查看 |
问题描述
今天想尝试下uniapp,碰到如下问题:
1、使用下面的vue命令行创建项目,等了15分钟才创建成功
vue create -p dcloudio/uni-preset-vue test
不知道有没有优化的办法,我的网络确定是没问题的。
2、uni.d.ts没有关于uni.request返回promise的定义,只有回调的方式。
3、uni.d.ts里uni.request返回数据的data属性定义有问题,建议使用any,否则vscode会提示类型错误。
系统信息:
vscode
npm run info
的运行结果]The text was updated successfully, but these errors were encountered: