美文网首页HarmonyOS
Type 'null' is not assignable to

Type 'null' is not assignable to

作者: survivorsfyh | 来源:发表于2024-05-28 15:07 被阅读0次

设置泛型将参数配置为 null 时抛出了如下异常:
Type 'null' is not assignable to type 'T'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'null'. <ArkTSCheck>

解决办法

在 null 后面添加 ! 即可,以表示该值不会为 null

data: T = null!

以上便是此次分享的全部内容,希望能对大家有所帮助!

相关文章

网友评论

    本文标题:Type 'null' is not assignable to

    本文链接:https://www.haomeiwen.com/subject/fezhqjtx.html