Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript strictNullChecks - Object is possibly 'null'

After enabling strictNullChecks with Angular 4.1.1, getting several errors for null checks. I have fixed bundles of them but unable to fix the same Object is possibly 'null' for this.form.get('username').value. Likewise others, I have tried the same but unable to fix the error.

if (this.form.get('username') != null) {
    body.append('username', this.form.get('username').value);
}
like image 512
Ali Shahzad Avatar asked May 05 '17 09:05

Ali Shahzad


1 Answers

Try using Non-null assertion operator like

this.form.get('username')!.value; // notice !
like image 190
yurzui Avatar answered Sep 20 '22 18:09

yurzui