in my Angular app i have a component:
filteredOptions: Observable<string[]>;
Following line give the error:
Property 'filteredOptions' has no initializer and is not definitely assigned in the constructor.
28 filteredOptions: Observable<string[]>;
it's because typescript 2.7.2
included a strict class checking where all properties should be declared in constructor. So to work around that you can:
name!:string;
"strictPropertyInitialization": false
to your compiler options.filteredOptions: Observable<string[]> | undefined;
filteredOptions?: Observable<string[]>
more details:
name!:string;
: compiler trust me on this, I will guarantee that it will not be undefined (can cause unpredicted behavior)"strictPropertyInitialization": false
: compiler stop your strict check everywhere pleasefilteredOptions
might or might not have a value. In that case, it's your responsibility to handle the undefined value in your case (use ?.
in your HTML templates, null
and undefined
check...etc.)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With