- 发布:2023-07-07 10:16
- 更新:2023-07-07 10:41
- 阅读:110
产品分类: uni小程序SDK
手机系统: 全部
手机厂商: 华为
页面类型: vue
SDK版本号: 3.8.4
测试过的手机:
操作步骤:
uni
.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
crop: {
quality: 60,
width: 140,
height: 140
}
})
.then(([_, res]) => { // 返回的数据与声明文件不同,坑死人了
})
uni
.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
crop: {
quality: 60,
width: 140,
height: 140
}
})
.then(([_, res]) => { // 返回的数据与声明文件不同,坑死人了
})
预期结果:
promise调用uni Api 返回数据要与类型声明一致
promise调用uni Api 返回数据要与类型声明一致
实际结果:
promise调用uni Api 返回数据要与类型声明不一致
promise调用uni Api 返回数据要与类型声明不一致
bug描述:
使用uni.xxx,promise调用,返回的数据结果是
[err, {xxx}]
为什么类型文件的定义是
declare namespace UniNamespace {
type PromisifySuccessResult<
P,
T extends {
success?: (...args: any[]) => void
},
R = void
> = P extends {
success: any
}
? R
: P extends { fail: any }
? R
: P extends { complete: any }
? R
: Promise<Parameters<Exclude<T['success'], undefined>>[0]>;
发现另一个声明是对的,为什么不使用?
type PromisifySuccessResultLegacy<
P,
T extends {
success?: (...args: any[]) => void
}
> = P extends {
success: any
}
? void
: P extends { fail: any }
? void
: P extends { complete: any }
? void
: Promise<ErrorFirstArray<Parameters<Exclude<T['success'], undefined>>[0]>>;
}
1***@qq.com (作者)
vue2
2023-07-07 10:21