HarmonyOS

Type 'null' is not assignable to

2024-05-28  本文已影响0人  survivorsfyh

设置泛型将参数配置为 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!

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

上一篇 下一篇

猜你喜欢

热点阅读