代码IDE提示编译报错:Type 'TextTest' is not assignable to type 'ITest<T>'.
Type ‘TextTest’ is not assignable to type ‘ITest<T>’. The types returned by ‘getContent()’ are incompatible between these types. Type ‘TextContent’ is not assignable to type ‘T’. ‘TextContent’ is assignable to the constraint of type ‘T’, but ‘T’ could be instantiated with a different subtype of constraint ‘BaseContent’. <ArkTSCheck>
interface ITest<T extends BaseContent> {
getContent(): T
}
class BaseContent {
}
class TextContent extends BaseContent {
}
class TextTest implements ITest<TextContent>{
getContent(): TextContent {
return new TextContent()
}
}
class ContentFactory{
static getTest<T extends BaseContent>():ITest<T>{
return new TextTest()
}
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
如何解决编译报错“Property xxx does not exist on type 'typeof BuildProfile'
6125浏览 • 1回复 待解决
报错Property 'pushUrl' does not exist on type 'typeof router'.
5117浏览 • 1回复 待解决
HarmonyOS TYPE_SYSTEM 和 TYPE_NAVIGATION_INDICATOR
957浏览 • 1回复 待解决
HarmonyOS 用reflect-metadata的@Type(()=> )报错
998浏览 • 1回复 待解决
编译工程提示“This device type does not match project profile.”或安装时出现 “DEVICE_NOT_SUPPORT_ER
558浏览 • 0回复 待解决
IDE登录报错,在IDE中运行模拟器,提示登录,登录后,网页提示成功,IDE提示Login Failed!
1203浏览 • 1回复 待解决
HarmonyOS 编译报错 'xxx' can't support crossplatform application
2118浏览 • 1回复 待解决
HarmonyOS type如何合并
962浏览 • 1回复 待解决
安装HAP包报错:“failed to install bundle. install debug type not same”
3477浏览 • 1回复 待解决
HarmonyOS IDE 编译报错:ArkTS ERROR:Duplicate identifier “index”
1781浏览 • 1回复 待解决
HarmonyOS 最新版Bate2新增的@Type和现有class-transformer里面的@Type冲突
891浏览 • 1回复 待解决
HarmonyOS 接口params传数组接口报错500 Content-Type应该怎么传
966浏览 • 1回复 待解决
hb build -T单独编译,应如何编译
5512浏览 • 1回复 待解决
编译构建报错,提示CONFIGURE_SDK_ERROR
1839浏览 • 1回复 待解决
BuildProfile自定义字段报错:Property 'BUILD_VERSION' does not exist on type 'typeof BuildProfile'
1760浏览 • 1回复 待解决
HarmonyOS TextInput 设置 type 后, showUnderline(true)无效
1951浏览 • 1回复 待解决
input_enter_key_type设置没生效
7143浏览 • 1回复 待解决
TextInput 中 showUnit 和 type(InputType.Number) 互斥吗?
1311浏览 • 1回复 待解决
http请求中能否不设置Content-Type参数
3276浏览 • 1回复 待解决
HarmonyOS IDE运行报错
996浏览 • 1回复 待解决
因为getTest函数返回类型是ITest<T>,修改成如下即可(增加as处理):