Closed
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When creating a fresh Angular v16.1.0 project, then adding Angular Material to the project, and finally adding the 'table' schematic to produce an example component, the component produces an Angular build warning error in line 20 of the html template stating that the '?.' operator can be replaced with the '.' operator.
Reproduction
StackBlitz link: Build Warning Error
Steps to reproduce:
- Create a fresh Angular v16.1.0 project:
ng new angular-material-ex2 --standalone
- Change directory:
cd angular-material-ex2/src/app
- Add Angular Material:
ng add @angular/material
- Generate the 'table' schematic:
ng g @angular/material:table MyTable
- Modify code to accept the newly-created MyTable
5.1 In app.component.ts file, change code line from:
imports: [CommonModule],
..to..
imports: [CommonModule, MyTableComponent],
5.2 In app.component.ts file, after the code line:
import { CommonModule } from '@angular/common';
..put an additional code line..
import { MyTableComponent } from './my-table/my-table.component'; - Build the project:
ng run build
- You will be presented with the Angular build warning error:
"Warning: src/app/my-table/my-table.component.html:20:29 - warning NG8107: The left side of this optional chain operation does not include 'null' or 'undefined' in its type, therefore the '?.' operator can be replaced with the '.' operator."
Note: The Stackblitz code sample should show the error - To fix, just remove the two Optional Chaining operators; i.e. the two question marks
Expected Behavior
No Build warning error will appear.
Actual Behavior
Code will compile with out any errors.
Environment
- Angular: 16.1.0
- CDK/Material: 16.1.1 / 16.1.1
- Browser(s): Any (Firefox & Chrome)
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11