代码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'
4277浏览 • 1回复 待解决
HarmonyOS 用reflect-metadata的@Type(()=> )报错
293浏览 • 1回复 待解决
报错Property 'pushUrl' does not exist on type 'typeof router'.
3978浏览 • 1回复 待解决
HarmonyOS TYPE_SYSTEM 和 TYPE_NAVIGATION_INDICATOR
425浏览 • 1回复 待解决
HarmonyOS type如何合并
444浏览 • 1回复 待解决
IDE登录报错,在IDE中运行模拟器,提示登录,登录后,网页提示成功,IDE提示Login Failed!
634浏览 • 1回复 待解决
HarmonyOS 编译报错 'xxx' can't support crossplatform application
484浏览 • 1回复 待解决
安装HAP包报错:“failed to install bundle. install debug type not same”
2666浏览 • 1回复 待解决
HarmonyOS IDE 编译报错:ArkTS ERROR:Duplicate identifier “index”
749浏览 • 1回复 待解决
HarmonyOS 最新版Bate2新增的@Type和现有class-transformer里面的@Type冲突
221浏览 • 1回复 待解决
input_enter_key_type设置没生效
6596浏览 • 1回复 待解决
HarmonyOS TextInput 设置 type 后, showUnderline(true)无效
1170浏览 • 1回复 待解决
BuildProfile自定义字段报错:Property 'BUILD_VERSION' does not exist on type 'typeof BuildProfile'
1106浏览 • 1回复 待解决
hb build -T单独编译,应如何编译
4402浏览 • 1回复 待解决
HarmonyOS 接口params传数组接口报错500 Content-Type应该怎么传
390浏览 • 1回复 待解决
编译构建报错,提示CONFIGURE_SDK_ERROR
1212浏览 • 1回复 待解决
HarmonyOS 无法使用class-transformer中的@Type注解
1132浏览 • 1回复 待解决
http请求中能否不设置Content-Type参数
2532浏览 • 1回复 待解决
因为getTest函数返回类型是ITest<T>,修改成如下即可(增加as处理):