zZZ1Ma
zZZ1Ma
  • 发布:2023-12-15 17:49
  • 更新:2024-07-10 21:03
  • 阅读:479

uni.request()返回值自定义泛型类型,如何消除爆红【类型“RequestSuccessCallbackResult”缺少类型“{...}"】?

分类:uni-app

封装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”...***  
}

语法有问题还是其它问题?

2023-12-15 17:49 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

0: Bundler.load() failed
20:52:17.369 1: Bundler.loader.load(/Users/baozhenyu/Downloads/gitWj/hbuilder/myApp/unpackage/dist/dev/.uvue/components/commonTypes/common.uts) failed
20:52:17.370 2:
20:52:17.370 x Index Signature is not supported.
20:52:17.370 at components/commonTypes/common.uts:38:1
20:52:17.370 35 | }
20:52:17.370 36 | export type formListType = formListObjType[]
20:52:17.370 37 | export interface formDataType {
20:52:17.370 38 | [key : string] : any
20:52:17.370 : ^
20:52:17.370 39 | }
20:52:17.370 40 | export interface comFormType extends UniElement {
20:52:17.370 41 | init : () => void;
20:52:17.370 `----
20:52:17.370
20:52:17.370 3: error was recoverable, but proceeding would result in wrong codegen
20:52:17.370 4: Syntax Error'

  • 2***@qq.com

    我的直接不支持什么意思?太离谱了,如果uts只是这种水平,完全不能用了

    2024-07-10 21:04

要回复问题请先登录注册