Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting error

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

at the line below

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

Making it optional using ? breaks code at other place where I use this.duni.nativeElement givingObject is possibly 'undefined'.ts(2532) . How can I solve this error without changing any property in the config files?

like image 960
Paritosh M Avatar asked Dec 06 '25 15:12

Paritosh M


1 Answers

Use the Non-null assertion operator

@ViewChild('bhondu') duni!: ElementRef<HTMLTableDataCellElement>;
like image 95
Yannick Beauchamp-H Avatar answered Dec 08 '25 03:12

Yannick Beauchamp-H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!