From fae509b7bb8ae849f9d574c59fccebd261b86ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Mon, 3 Jun 2024 17:25:17 +0800 Subject: [PATCH] Update uts-for-android.md --- docs/plugin/uts-for-android.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/plugin/uts-for-android.md b/docs/plugin/uts-for-android.md index 03fffaac..2ce81db3 100644 --- a/docs/plugin/uts-for-android.md +++ b/docs/plugin/uts-for-android.md @@ -1285,6 +1285,38 @@ function getAppName(context : Context) : string { } ``` +### 6.6 泛型传递丢失的问题 + +如果在UTS中声明一个包含泛型声明的方法,可能会出现泛型丢失,原因是因为普通的kotlin 方法没有实现泛型的传递 + +错误的kt代码: + +```kotlin +fun getArtListByres(): A? { + var aRet = UTSAndroid.consoleDebugError(JSON.parse>("{\"x\":111,\"y\":\"aaa\",\"t\":{\"name\":\"zhangsan\"}}"), " at pages/index/index.uvue:27"); + return aRet; +} +``` + +期望得到的正确的kt代码: + +```ts +inline fun getArtListByres(): A? { + var aRet = UTSAndroid.consoleDebugError(JSON.parse>("{\"x\":111,\"y\":\"aaa\",\"t\":{\"name\":\"zhangsan\"}}"), " at pages/index/index.uvue:27"); + return aRet; +} +``` + +为了解决这种情况,我们可以在UTS中 添加android方法注解,来告诉编译器生成正确的代码: + +```kotlin +@UTSAndroid.keyword("inline") +@UTSAndroid.keyword('reified') +export function request(options : RequestOptions) : RequestTask { + //xxx +} +``` + ## 7 已知待解决问题(持续更新) -- GitLab