Skip to content

Commit 4cb1d68

Browse files
committed
refactor(cdk/table): fix strict property initialization errors
Updates the code to be compatible with strict property initialization.
1 parent 693751e commit 4cb1d68

File tree

5 files changed

+65
-65
lines changed

5 files changed

+65
-65
lines changed

src/cdk/table/cell.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class CdkColumnDef implements CanStick {
8989
set name(name: string) {
9090
this._setNameInput(name);
9191
}
92-
protected _name: string;
92+
protected _name!: string;
9393

9494
/** Whether the cell is sticky. */
9595
@Input({transform: booleanAttribute})
@@ -122,26 +122,26 @@ export class CdkColumnDef implements CanStick {
122122
_stickyEnd: boolean = false;
123123

124124
/** @docs-private */
125-
@ContentChild(CdkCellDef) cell: CdkCellDef;
125+
@ContentChild(CdkCellDef) cell!: CdkCellDef;
126126

127127
/** @docs-private */
128-
@ContentChild(CdkHeaderCellDef) headerCell: CdkHeaderCellDef;
128+
@ContentChild(CdkHeaderCellDef) headerCell!: CdkHeaderCellDef;
129129

130130
/** @docs-private */
131-
@ContentChild(CdkFooterCellDef) footerCell: CdkFooterCellDef;
131+
@ContentChild(CdkFooterCellDef) footerCell!: CdkFooterCellDef;
132132

133133
/**
134134
* Transformed version of the column name that can be used as part of a CSS classname. Excludes
135135
* all non-alphanumeric characters and the special characters '-' and '_'. Any characters that
136136
* do not match are replaced by the '-' character.
137137
*/
138-
cssClassFriendlyName: string;
138+
cssClassFriendlyName!: string;
139139

140140
/**
141141
* Class name for cells in this column.
142142
* @docs-private
143143
*/
144-
_columnCssClassName: string[];
144+
_columnCssClassName!: string[];
145145

146146
constructor(...args: unknown[]);
147147
constructor() {}

src/cdk/table/row.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export abstract class BaseRowDef implements OnChanges {
4343
protected _differs = inject(IterableDiffers);
4444

4545
/** The columns to be displayed on this row. */
46-
columns: Iterable<string>;
46+
columns!: Iterable<string>;
4747

4848
/** Differ used to check if any changes were made to the columns. */
49-
protected _columnsDiffer: IterableDiffer<any>;
49+
protected _columnsDiffer!: IterableDiffer<any>;
5050

5151
constructor(...args: unknown[]);
5252
constructor() {}
@@ -205,7 +205,7 @@ export class CdkRowDef<T> extends BaseRowDef {
205205
* when no other when functions return true for the data.
206206
* For every row, there must be at least one when function that passes or an undefined to default.
207207
*/
208-
when: (index: number, rowData: T) => boolean;
208+
when!: (index: number, rowData: T) => boolean;
209209

210210
constructor(...args: unknown[]);
211211

@@ -282,7 +282,7 @@ export class CdkCellOutlet implements OnDestroy {
282282
_viewContainer = inject(ViewContainerRef);
283283

284284
/** The ordered list of cells to render within this outlet's view container */
285-
cells: CdkCellDef[];
285+
cells!: CdkCellDef[];
286286

287287
/** The data context to be provided to each cell */
288288
context: any;

src/cdk/table/table.spec.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ class SimpleCdkTableApp {
22092209
columnsToRender = ['column_a', 'column_b', 'column_c'];
22102210
contentChangedCount = 0;
22112211

2212-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2212+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
22132213
}
22142214

22152215
@Component({
@@ -2240,7 +2240,7 @@ class CdkTableWithDifferentDataInputsApp {
22402240
dataSource: DataSource<TestData> | Observable<TestData[]> | TestData[] | any = null;
22412241
columnsToRender = ['column_a', 'column_b', 'column_c'];
22422242

2243-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2243+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
22442244
}
22452245

22462246
@Component({
@@ -2375,7 +2375,7 @@ class WhenRowCdkTableApp {
23752375
this.dataSource.addData();
23762376
}
23772377

2378-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2378+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
23792379

23802380
showIndexColumns() {
23812381
const indexColumns = ['index', 'dataIndex', 'renderIndex'];
@@ -2480,7 +2480,7 @@ class WhenRowWithoutDefaultCdkTableApp {
24802480
isIndex1 = (index: number, _rowData: TestData) => index == 1;
24812481
hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3';
24822482

2483-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2483+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
24842484
}
24852485

24862486
@Component({
@@ -2524,7 +2524,7 @@ class WhenRowMultipleDefaultsCdkTableApp {
25242524
columnsToRender = ['column_a', 'column_b', 'column_c'];
25252525
hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3';
25262526

2527-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2527+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
25282528
}
25292529

25302530
@Component({
@@ -2542,10 +2542,10 @@ class WhenRowMultipleDefaultsCdkTableApp {
25422542
imports: [CdkTableModule],
25432543
})
25442544
class DynamicDataSourceCdkTableApp {
2545-
dataSource: FakeDataSource;
2545+
dataSource!: FakeDataSource;
25462546
columnsToRender = ['column_a'];
25472547

2548-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2548+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
25492549
}
25502550

25512551
@Component({
@@ -2573,7 +2573,7 @@ class TrackByCdkTableApp {
25732573
dataSource = new FakeDataSource();
25742574
columnsToRender = ['column_a', 'column_b'];
25752575

2576-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2576+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
25772577

25782578
trackBy = (index: number, item: TestData) => {
25792579
switch (this.trackByStrategy) {
@@ -2656,7 +2656,7 @@ class StickyFlexLayoutCdkTableApp extends StickyPositioningListenerTest {
26562656
dataSource = new FakeDataSource();
26572657
columns = ['column-1', 'column-2', 'column-3', 'column-4', 'column-5', 'column-6'];
26582658

2659-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2659+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
26602660

26612661
dir: Direction = 'ltr';
26622662
stickyHeaders: string[] = [];
@@ -2713,7 +2713,7 @@ class StickyNativeLayoutCdkTableApp extends StickyPositioningListenerTest {
27132713
dataSource = new FakeDataSource();
27142714
columns = ['column-1', 'column-2', 'column-3', 'column-4', 'column-5', 'column-6'];
27152715

2716-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2716+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
27172717

27182718
stickyHeaders: string[] = [];
27192719
stickyFooters: string[] = [];
@@ -2745,7 +2745,7 @@ class DynamicColumnDefinitionsCdkTableApp {
27452745
dynamicColumns: any[] = [];
27462746
dataSource = new FakeDataSource();
27472747

2748-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2748+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
27492749
}
27502750

27512751
@Component({
@@ -2766,7 +2766,7 @@ class CustomRoleCdkTableApp {
27662766
dataSource = new FakeDataSource();
27672767
columnsToRender = ['column_a'];
27682768

2769-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2769+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
27702770
}
27712771

27722772
@Component({
@@ -2787,7 +2787,7 @@ class CrazyColumnNameCdkTableApp {
27872787
dataSource = new FakeDataSource();
27882788
columnsToRender = ['crazy-column-NAME-1!@#$%^-_&*()2'];
27892789

2790-
@ViewChild(CdkTable) table: CdkTable<TestData>;
2790+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
27912791
}
27922792

27932793
@Component({
@@ -2846,7 +2846,7 @@ class MissingColumnDefCdkTableApp {
28462846
imports: [CdkTableModule],
28472847
})
28482848
class MissingColumnDefAfterRenderCdkTableApp implements AfterViewInit {
2849-
dataSource: FakeDataSource;
2849+
dataSource!: FakeDataSource;
28502850
displayedColumns: string[] = [];
28512851
cdr = inject(ChangeDetectorRef);
28522852

@@ -2945,7 +2945,7 @@ class MissingFooterRowDefCdkTableApp {
29452945
imports: [CdkTableModule],
29462946
})
29472947
class UndefinedColumnsCdkTableApp {
2948-
undefinedColumns: string[];
2948+
undefinedColumns: string[] | undefined;
29492949
dataSource = new FakeDataSource();
29502950
}
29512951

@@ -3006,15 +3006,15 @@ class RowContextCdkTableApp {
30063006
imports: [CdkTableModule],
30073007
})
30083008
class WrapperCdkTableApp<T> implements AfterContentInit {
3009-
@ContentChildren(CdkColumnDef, {descendants: false}) columnDefs: QueryList<CdkColumnDef>;
3010-
@ContentChild(CdkHeaderRowDef) headerRowDef: CdkHeaderRowDef;
3011-
@ContentChildren(CdkRowDef, {descendants: false}) rowDefs: QueryList<CdkRowDef<T>>;
3012-
@ContentChild(CdkNoDataRow) noDataRow: CdkNoDataRow;
3009+
@ContentChildren(CdkColumnDef, {descendants: false}) columnDefs!: QueryList<CdkColumnDef>;
3010+
@ContentChild(CdkHeaderRowDef) headerRowDef!: CdkHeaderRowDef;
3011+
@ContentChildren(CdkRowDef, {descendants: false}) rowDefs!: QueryList<CdkRowDef<T>>;
3012+
@ContentChild(CdkNoDataRow) noDataRow!: CdkNoDataRow;
30133013

3014-
@ViewChild(CdkTable, {static: true}) table: CdkTable<T>;
3014+
@ViewChild(CdkTable, {static: true}) table!: CdkTable<T>;
30153015

3016-
@Input() columns: string[];
3017-
@Input() dataSource: DataSource<T>;
3016+
@Input() columns!: string[];
3017+
@Input() dataSource!: DataSource<T>;
30183018

30193019
ngAfterContentInit() {
30203020
// Register the content's column, row, and header row definitions.
@@ -3092,7 +3092,7 @@ class NativeHtmlTableApp {
30923092
dataSource = new FakeDataSource();
30933093
columnsToRender = ['column_a', 'column_b', 'column_c'];
30943094

3095-
@ViewChild(CdkTable) table: CdkTable<TestData>;
3095+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
30963096
}
30973097

30983098
@Component({
@@ -3171,7 +3171,7 @@ class NativeTableWithNoHeaderOrFooterRows {
31713171
dataSource = new FakeDataSource();
31723172
columnsToRender = ['column_a', 'column_b', 'column_c'];
31733173

3174-
@ViewChild(CdkTable) table: CdkTable<TestData>;
3174+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
31753175
}
31763176

31773177
@Component({
@@ -3193,7 +3193,7 @@ class NativeHtmlTableWithCaptionApp {
31933193
dataSource = new FakeDataSource();
31943194
columnsToRender = ['column_a'];
31953195

3196-
@ViewChild(CdkTable) table: CdkTable<TestData>;
3196+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
31973197
}
31983198

31993199
@Component({
@@ -3222,7 +3222,7 @@ class NativeHtmlTableWithColgroupAndCol {
32223222
dataSource = new FakeDataSource();
32233223
columnsToRender = ['column_a', 'column_b'];
32243224

3225-
@ViewChild(CdkTable) table: CdkTable<TestData>;
3225+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
32263226
}
32273227

32283228
@Component({
@@ -3276,7 +3276,7 @@ class TableWithIndirectDescendantDefs {
32763276
imports: [CdkTableModule],
32773277
})
32783278
class NativeHtmlTableAppOnPush {
3279-
@Input() dataSource: FakeDataSource;
3279+
@Input() dataSource!: FakeDataSource;
32803280
columnsToRender = ['column_a', 'column_b', 'column_c'];
32813281
}
32823282

@@ -3327,8 +3327,8 @@ class WrapNativeHtmlTableAppOnPush {
33273327
`,
33283328
})
33293329
class TableWithVirtualScroll {
3330-
@ViewChild(CdkTable) table: CdkTable<TestData>;
3331-
@ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport;
3330+
@ViewChild(CdkTable) table!: CdkTable<TestData>;
3331+
@ViewChild(CdkVirtualScrollViewport) viewport!: CdkVirtualScrollViewport;
33323332
dataSource = new FakeDataSource();
33333333
columnsToRender = ['column_a', 'column_b', 'column_c'];
33343334
isFixedLayout = signal(true);

0 commit comments

Comments
 (0)