代码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'
3277浏览 • 1回复 待解决
报错Property 'pushUrl' does not exist on type 'typeof router'.
3621浏览 • 1回复 待解决
IDE登录报错,在IDE中运行模拟器,提示登录,登录后,网页提示成功,IDE提示Login Failed!
149浏览 • 1回复 待解决
安装HAP包报错:“failed to install bundle. install debug type not same”
2248浏览 • 1回复 待解决
BuildProfile自定义字段报错:Property 'BUILD_VERSION' does not exist on type 'typeof BuildProfile'
744浏览 • 1回复 待解决
input_enter_key_type设置没生效
6465浏览 • 1回复 待解决
HarmonyOS TextInput 设置 type 后, showUnderline(true)无效
797浏览 • 1回复 待解决
HarmonyOS IDE 编译报错:ArkTS ERROR:Duplicate identifier “index”
127浏览 • 1回复 待解决
编译构建报错,提示CONFIGURE_SDK_ERROR
744浏览 • 1回复 待解决
hb build -T单独编译,应如何编译
3794浏览 • 1回复 待解决
HarmonyOS 无法使用class-transformer中的@Type注解
634浏览 • 1回复 待解决
Android WindowManager.LayoutParams.TYPE_PHONE;和鸿蒙用那个代替?
5088浏览 • 1回复 待解决
TextInput type类型为InputType.Number时不能输入空格?
394浏览 • 1回复 待解决
export type不支持后,是否有平替方式?
705浏览 • 1回复 待解决
Cannot find module '@ohos.application.Ability' or its corresponding type declarations.
11977浏览 • 1回复 待解决
HarmonyOS IDE 汉化和自动提示
123浏览 • 1回复 待解决
TextInput 中 showUnit 和 type(InputType.Number) 互斥吗?
355浏览 • 1回复 待解决
http请求中能否不设置Content-Type参数
2153浏览 • 1回复 待解决
因为getTest函数返回类型是ITest<T>,修改成如下即可(增加as处理):