w***@outlook.com
w***@outlook.com
  • 发布:2025-05-19 14:42
  • 更新:2025-05-19 14:42
  • 阅读:43

UTS 插件参数为Function时无法调用

分类:uts

Hbuilderx 版本: 4.65

问题:
在UTS中创建了方法提供给外部调用,参数对象中含有Function,会调用失败,将前端调用传入的参数识别成 Integer

My2ApiOptions .<init> argument 2 has type kotlin.jvm.functions.Function1, got java.lang.Integer

但是如果用的是生成的模板中的对象 MyApiOptions 则没有问题,无论在里面添加什么参数都可以正常调用,但是如果修改了这个对象的名字,或者是复制一份都不行,我无法理解这是什么情况;只能使用多个参数的调用形式。

代码如下:

interface.uts

export type MyApiOptions = {  
    names ?: string  
    success ?: (res : MyApiResult) => void  
    fail ?: (res : MyApiFail) => void  
    complete ?: (res : any) => void  
}  

export type My2ApiOptions = {  
    names ?: string  
    success ?: (res : MyApiResult) => void  
    fail ?: (res : MyApiFail) => void  
    complete ?: (res : any) => void  
}  

export type MyApi = (options : (res : any) => void) => void  

export type My1Api = (options : MyApiOptions ) => void  

export type My2Api = (options : (res : any) => void, names: string) => void  

export type My3Api = (options :My2ApiOptions) => void

index.uts

export const myApi: MyApi = function (options) {……}  

export const my1Api: My1Api = function (options: MyApiOptions) {……}  

export const my2Api: My2Api = function (options, names) {……}  

export const my3Api: My3Api = function (options: My2ApiOptions) {……}

前端App.vue


// 执行成功  
myApi(success: (res) => {})  

// 执行成功  
my1Api({  
   name: '123',  
   success: (res) => {}  
})  

// 执行成功  
my2Api( '123', success: (res) => {})  

// 执行失败, argument 2 has type kotlin.jvm.functions.Function1, got java.lang.Integer  
my3Api({  
   name: '123',  
   success: (res) => {}  
})  
2025-05-19 14:42 负责人:无 分享
已邀请:

要回复问题请先登录注册