Skip to content

bug(Table Schematic Code): Build warning error in the 'table' schematic code #27329

Closed
@bradws

Description

@bradws

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:

  1. Create a fresh Angular v16.1.0 project:

ng new angular-material-ex2 --standalone

  1. Change directory:

cd angular-material-ex2/src/app

  1. Add Angular Material:

ng add @angular/material

  1. Generate the 'table' schematic:

ng g @angular/material:table MyTable

  1. 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';
  2. Build the project:

ng run build

  1. 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
  2. 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

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsarea: material/table

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions