繁体   English   中英

如何解决 typescript 错误“x”没有初始化程序并且未在构造函数中明确分配?

[英]How can I solve typescript error 'x' has no initializer and is not definitely assigned in the constructor?

我收到错误

Property 'duni' has no initializer and is not definitely assigned in the constructor.ts(2564)

在下面的行

  @ViewChild('bhondu') duni: ElementRef<HTMLTableDataCellElement>;

使用? 在我使用this.duni.nativeElement的其他地方中断代码,给出Object is possibly 'undefined'.ts(2532) 如何在不更改配置文件中的任何属性的情况下解决此错误?

使用非空断言运算符

@ViewChild('bhondu') duni!: ElementRef<HTMLTableDataCellElement>;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM