Skip to content

Commit c2449f7

Browse files
committed
refactor(cdk-experimental/selection): fix strict property initialization errors
Updates the code to be compatible with strict property initialization.
1 parent 67dc545 commit c2449f7

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/cdk-experimental/selection/selection-column.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export class CdkSelectionColumn<T> implements OnInit, OnDestroy {
7979

8080
this._syncColumnDefName();
8181
}
82-
private _name: string;
82+
private _name!: string;
8383

84-
@ViewChild(CdkColumnDef, {static: true}) private readonly _columnDef: CdkColumnDef;
85-
@ViewChild(CdkCellDef, {static: true}) private readonly _cell: CdkCellDef;
86-
@ViewChild(CdkHeaderCellDef, {static: true}) private readonly _headerCell: CdkHeaderCellDef;
84+
@ViewChild(CdkColumnDef, {static: true}) private readonly _columnDef!: CdkColumnDef;
85+
@ViewChild(CdkCellDef, {static: true}) private readonly _cell!: CdkCellDef;
86+
@ViewChild(CdkHeaderCellDef, {static: true}) private readonly _headerCell!: CdkHeaderCellDef;
8787

8888
ngOnInit() {
8989
if (!this.selection && (typeof ngDevMode === 'undefined' || ngDevMode)) {

src/cdk-experimental/selection/selection-toggle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CdkSelectionToggle<T> implements OnDestroy, OnInit {
3333
private _controlValueAccessors = inject(NG_VALUE_ACCESSOR, {optional: true, self: true});
3434

3535
/** The value that is associated with the toggle */
36-
@Input('cdkSelectionToggleValue') value: T;
36+
@Input('cdkSelectionToggleValue') value!: T;
3737

3838
/** The index of the value in the list. Required when used with `trackBy` */
3939
@Input('cdkSelectionToggleIndex')

src/cdk-experimental/selection/selection.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class ListWithMultiSelection {
434434
private readonly _elementRef = inject(ElementRef);
435435
private readonly _cdr = inject(ChangeDetectorRef);
436436

437-
@ViewChild(CdkSelection) cdkSelection: CdkSelection<string>;
437+
@ViewChild(CdkSelection) cdkSelection!: CdkSelection<string>;
438438

439439
data = ['apple', 'banana', 'cherry', 'durian'];
440440

@@ -498,7 +498,7 @@ class ListWithSingleSelection {
498498
private readonly _elementRef = inject(ElementRef);
499499
private readonly _cdr = inject(ChangeDetectorRef);
500500

501-
@ViewChild(CdkSelection) cdkSelection: CdkSelection<string>;
501+
@ViewChild(CdkSelection) cdkSelection!: CdkSelection<string>;
502502

503503
data = ['apple', 'banana', 'cherry', 'durian'];
504504
selectionChange?: SelectionChange<string>;
@@ -539,7 +539,7 @@ class MultiSelectTableWithSelectionColumn {
539539
readonly elementRef = inject(ElementRef);
540540
private readonly _cdr = inject(ChangeDetectorRef);
541541

542-
@ViewChild(CdkSelection) cdkSelection: CdkSelection<string>;
542+
@ViewChild(CdkSelection) cdkSelection!: CdkSelection<string>;
543543

544544
columns = ['select', 'name'];
545545
data = ['apple', 'banana', 'cherry', 'durian'];
@@ -606,7 +606,7 @@ class SingleSelectTableWithSelectionColumn {
606606
readonly elementRef = inject(ElementRef);
607607
private readonly _cdr = inject(ChangeDetectorRef);
608608

609-
@ViewChild(CdkSelection) cdkSelection: CdkSelection<string>;
609+
@ViewChild(CdkSelection) cdkSelection!: CdkSelection<string>;
610610

611611
columns = ['select', 'name'];
612612
data = ['apple', 'banana', 'cherry', 'durian'];

src/cdk-experimental/selection/selection.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {SelectableWithIndex, SelectionChange, SelectionSet} from './selection-se
3434
exportAs: 'cdkSelection',
3535
})
3636
export class CdkSelection<T> implements OnInit, AfterContentChecked, CollectionViewer, OnDestroy {
37-
viewChange: Observable<ListRange>;
37+
viewChange!: Observable<ListRange>;
3838

3939
@Input()
4040
get dataSource(): TableDataSource<T> {
@@ -45,9 +45,9 @@ export class CdkSelection<T> implements OnInit, AfterContentChecked, CollectionV
4545
this._switchDataSource(dataSource);
4646
}
4747
}
48-
private _dataSource: TableDataSource<T>;
48+
private _dataSource!: TableDataSource<T>;
4949

50-
@Input('trackBy') trackByFn: TrackByFunction<T>;
50+
@Input('trackBy') trackByFn!: TrackByFunction<T>;
5151

5252
/** Whether to support multiple selection */
5353
@Input('cdkSelectionMultiple')
@@ -57,20 +57,20 @@ export class CdkSelection<T> implements OnInit, AfterContentChecked, CollectionV
5757
set multiple(multiple: BooleanInput) {
5858
this._multiple = coerceBooleanProperty(multiple);
5959
}
60-
protected _multiple: boolean;
60+
protected _multiple: boolean = false;
6161

6262
/** Emits when selection changes. */
6363
@Output('cdkSelectionChange') readonly change = new EventEmitter<SelectionChange<T>>();
6464

6565
/** Latest data provided by the data source. */
66-
private _data: T[] | readonly T[];
66+
private _data!: T[] | readonly T[];
6767

6868
/** Subscription that listens for the data provided by the data source. */
69-
private _renderChangeSubscription: Subscription | null;
69+
private _renderChangeSubscription: Subscription | null = null;
7070

7171
private _destroyed = new Subject<void>();
7272

73-
private _selection: SelectionSet<T>;
73+
private _selection!: SelectionSet<T>;
7474

7575
private _switchDataSource(dataSource: TableDataSource<T>) {
7676
this._data = [];

0 commit comments

Comments
 (0)