Skip to content

bug(material/schematics): table schematic does not generate code that works with strict mode #21981

@Splaktar

Description

@Splaktar

Reproduction

Steps to reproduce:

  1. ng new with strict mode on
  2. ng add @angular/material
  3. ng g @angular/material:table table
  4. npm start

Expected Behavior

What behavior were you expecting to see?
The app should build and work.

Actual Behavior

What behavior did you actually see?

Error: src/app/table/table-datasource.ts:44:3 - error TS2564: Property 'paginator' has no initializer and is not definitely assigned in the constructor.

44   paginator: MatPaginator;
     ~~~~~~~~~


Error: src/app/table/table-datasource.ts:45:3 - error TS2564: Property 'sort' has no initializer and is not definitely assigned in the constructor.

45   sort: MatSort;
     ~~~~


Error: src/app/table/table.component.ts:13:28 - error TS2564: Property 'paginator' has no initializer and is not definitely assigned in the constructor.

13   @ViewChild(MatPaginator) paginator: MatPaginator;
                              ~~~~~~~~~


Error: src/app/table/table.component.ts:14:23 - error TS2564: Property 'sort' has no initializer and is not definitely assigned in the constructor.

14   @ViewChild(MatSort) sort: MatSort;
                         ~~~~


Error: src/app/table/table.component.ts:15:24 - error TS2564: Property 'table' has no initializer and is not definitely assigned in the constructor.
[39m[0m
15   @ViewChild(MatTable) table: MatTable<TableItem>;
                          ~~~~~


Error: src/app/table/table.component.ts:16:3 - error TS2564: Property 'dataSource' has no initializer and is not definitely assigned in the constructor.

16   dataSource: TableDataSource;
     ~~~~~~~~~~


Error: src/app/table/table.component.html:20:34 - error TS2532: Object is possibly 'undefined'.

20       [length]="dataSource?.data.length"
                                    ~~~~~~

  src/app/table/table.component.ts:9:16
    9   templateUrl: './table.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component TableComponent.

Environment

  • Angular: 11.2.1
  • CDK/Material: 11.2.1
  • Browser(s): N/A
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS Catalina

Relates to #17135

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: ng-generateSchematics that generate code in user projects

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions