封装requestHook,返回值传入泛型,编辑器爆红:
**官方声明文件源码:**
// request.d.ts
interface RequestSuccessCallbackResult {
data: string | AnyObject | ArrayBuffer;
statusCode: number;
header: any;
cookies: string[];
}
// commom.d.ts
interface AnyObject {
[key: string]: any; // ***此处爆红:类型“string”的索引签名重复。***
}
---------------------------------------------
**极简代码:**
// @/hooks/request/index.ts
interface UniRequestSuccessRespone<T> extends UniApp.RequestSuccessCallbackResult {
data : T
}
type ListData = {
page ?: number
limit ?: number
}
type ListResult = UniRequestSuccessRespone<{
count : number
ststus : number
productList : any
errMsg : string
}>['data']
const getProductList = (data ?: ListData) : Promise<ListResult> => {
return uni.request({ data, url: 'product/list' })
// ***爆红:不能将类型“Promise”分配给类型“Promise”...***
}
语法有问题还是其它问题?
2***@qq.com
我的直接不支持什么意思?太离谱了,如果uts只是这种水平,完全不能用了
2024-07-10 21:04