Skip to content

Commit 045f126

Browse files
committed
refactor(material/tree): fix strict property initialization errors
Updates the code to be compatible with strict property initialization.
1 parent 7bd5121 commit 045f126

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed

src/material/tree/node.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class MatTreeNode<T, K = T> extends CdkTreeNode<T, K> implements OnInit,
7272
// If the specified tabIndex value is null or undefined, fall back to the default value.
7373
this._tabIndexInputBinding = value;
7474
}
75-
private _tabIndexInputBinding: number;
75+
private _tabIndexInputBinding!: number;
7676

7777
/**
7878
* The default tabindex of the tree node.
@@ -135,7 +135,7 @@ export class MatTreeNode<T, K = T> extends CdkTreeNode<T, K> implements OnInit,
135135
providers: [{provide: CdkTreeNodeDef, useExisting: MatTreeNodeDef}],
136136
})
137137
export class MatTreeNodeDef<T> extends CdkTreeNodeDef<T> {
138-
@Input('matTreeNode') data: T;
138+
@Input('matTreeNode') data!: T;
139139
}
140140

141141
/**
@@ -158,7 +158,7 @@ export class MatNestedTreeNode<T, K = T>
158158
extends CdkNestedTreeNode<T, K>
159159
implements AfterContentInit, OnDestroy, OnInit
160160
{
161-
@Input('matNestedTreeNode') node: T;
161+
@Input('matNestedTreeNode') node!: T;
162162

163163
/**
164164
* Whether the node is disabled.
@@ -185,7 +185,7 @@ export class MatNestedTreeNode<T, K = T>
185185
// If the specified tabIndex value is null or undefined, fall back to the default value.
186186
this._tabIndex = value;
187187
}
188-
private _tabIndex: number;
188+
private _tabIndex!: number;
189189

190190
// This is a workaround for https://github.com/angular/angular/issues/19145
191191
// In aot mode, the lifecycle hooks from parent class are not called.

src/material/tree/tree-using-legacy-key-manager.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ class SimpleMatTreeApp {
110110
/** Value passed to tabindex attribute binding of each tree node. Null by default. */
111111
tabindexAttributeBinding: string | null = null;
112112

113-
@ViewChild('tree', {read: ElementRef}) tree: ElementRef<HTMLElement>;
114-
@ViewChildren('node') treeNodes: QueryList<ElementRef<HTMLElement>>;
113+
@ViewChild('tree', {read: ElementRef}) tree!: ElementRef<HTMLElement>;
114+
@ViewChildren('node') treeNodes!: QueryList<ElementRef<HTMLElement>>;
115115
}

src/material/tree/tree-using-tree-control.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,13 @@ describe('MatTree', () => {
661661
});
662662

663663
export class TestData {
664-
pizzaTopping: string;
665-
pizzaCheese: string;
666-
pizzaBase: string;
667-
level: number;
668-
children: TestData[];
669-
observableChildren: BehaviorSubject<TestData[]>;
670-
isSpecial: boolean;
664+
pizzaTopping!: string;
665+
pizzaCheese!: string;
666+
pizzaBase!: string;
667+
level!: number;
668+
children!: TestData[];
669+
observableChildren!: BehaviorSubject<TestData[]>;
670+
isSpecial = false;
671671
isDisabled?: boolean;
672672

673673
constructor(
@@ -879,7 +879,7 @@ class SimpleMatTreeApp {
879879

880880
underlyingDataSource = new FakeDataSource();
881881

882-
@ViewChild(MatTree) tree: MatTree<TestData>;
882+
@ViewChild(MatTree) tree!: MatTree<TestData>;
883883

884884
constructor() {
885885
this.underlyingDataSource.connect().subscribe(data => {
@@ -973,8 +973,8 @@ class MatTreeWithNullOrUndefinedChild {
973973
imports: [MatTreeModule],
974974
})
975975
class MatNestedTreeWithNullOrUndefinedChild {
976-
treeControl: NestedTreeControl<FoodNode>;
977-
dataSource: MatTreeNestedDataSource<FoodNode>;
976+
treeControl!: NestedTreeControl<FoodNode>;
977+
dataSource!: MatTreeNestedDataSource<FoodNode>;
978978

979979
constructor() {
980980
this.treeControl = new NestedTreeControl<FoodNode>(this._getChildren);
@@ -1008,7 +1008,7 @@ class NestedMatTreeApp {
10081008
dataSource = new MatTreeNestedDataSource<TestData>();
10091009
underlyingDataSource = new FakeDataSource();
10101010

1011-
@ViewChild(MatTree) tree: MatTree<TestData>;
1011+
@ViewChild(MatTree) tree!: MatTree<TestData>;
10121012

10131013
constructor() {
10141014
this.underlyingDataSource.connect().subscribe(data => {
@@ -1045,7 +1045,7 @@ class WhenNodeNestedMatTreeApp {
10451045
dataSource = new MatTreeNestedDataSource<TestData>();
10461046
underlyingDataSource = new FakeDataSource();
10471047

1048-
@ViewChild(MatTree) tree: MatTree<TestData>;
1048+
@ViewChild(MatTree) tree!: MatTree<TestData>;
10491049

10501050
constructor() {
10511051
this.underlyingDataSource.connect().subscribe(data => {
@@ -1091,7 +1091,7 @@ class MatTreeAppWithToggle {
10911091
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
10921092
underlyingDataSource = new FakeDataSource();
10931093

1094-
@ViewChild(MatTree) tree: MatTree<TestData>;
1094+
@ViewChild(MatTree) tree!: MatTree<TestData>;
10951095

10961096
constructor() {
10971097
this.underlyingDataSource.connect().subscribe(data => {
@@ -1128,7 +1128,7 @@ class NestedMatTreeAppWithToggle {
11281128
dataSource = new MatTreeNestedDataSource<TestData>();
11291129
underlyingDataSource = new FakeDataSource();
11301130

1131-
@ViewChild(MatTree) tree: MatTree<TestData>;
1131+
@ViewChild(MatTree) tree!: MatTree<TestData>;
11321132

11331133
constructor() {
11341134
this.underlyingDataSource.connect().subscribe(data => {
@@ -1177,7 +1177,7 @@ class WhenNodeMatTreeApp {
11771177
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
11781178
underlyingDataSource = new FakeDataSource();
11791179

1180-
@ViewChild(MatTree) tree: MatTree<TestData>;
1180+
@ViewChild(MatTree) tree!: MatTree<TestData>;
11811181

11821182
constructor() {
11831183
this.underlyingDataSource.connect().subscribe(data => {

src/material/tree/tree.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,13 @@ describe('MatTree', () => {
663663
});
664664

665665
export class TestData {
666-
pizzaTopping: string;
667-
pizzaCheese: string;
668-
pizzaBase: string;
669-
level: number;
670-
children: TestData[];
671-
observableChildren: BehaviorSubject<TestData[]>;
672-
isSpecial: boolean;
666+
pizzaTopping!: string;
667+
pizzaCheese!: string;
668+
pizzaBase!: string;
669+
level!: number;
670+
children!: TestData[];
671+
observableChildren!: BehaviorSubject<TestData[]>;
672+
isSpecial = false;
673673
isDisabled?: boolean;
674674

675675
constructor(
@@ -867,7 +867,7 @@ class SimpleMatTreeApp {
867867

868868
dataSource = new FakeDataSource();
869869

870-
@ViewChild(MatTree) tree: MatTree<TestData>;
870+
@ViewChild(MatTree) tree!: MatTree<TestData>;
871871
}
872872

873873
interface FoodNode {
@@ -912,7 +912,7 @@ const TREE_DATA: FoodNode[] = [
912912
})
913913
class MatTreeWithNullOrUndefinedChild {
914914
childrenAccessor = (node: FoodNode): FoodNode[] => node.children || [];
915-
dataSource: MatTreeNestedDataSource<FoodNode>;
915+
dataSource!: MatTreeNestedDataSource<FoodNode>;
916916

917917
constructor() {
918918
this.dataSource = new MatTreeNestedDataSource();
@@ -933,7 +933,7 @@ class MatTreeWithNullOrUndefinedChild {
933933
})
934934
class MatNestedTreeWithNullOrUndefinedChild {
935935
childrenAccessor = (node: FoodNode): FoodNode[] => node.children || [];
936-
dataSource: MatTreeNestedDataSource<FoodNode>;
936+
dataSource!: MatTreeNestedDataSource<FoodNode>;
937937

938938
constructor() {
939939
this.dataSource = new MatTreeNestedDataSource();
@@ -962,7 +962,7 @@ class NestedMatTreeApp {
962962
dataSource = new MatTreeNestedDataSource<TestData>();
963963
underlyingDataSource = new FakeDataSource();
964964

965-
@ViewChild(MatTree) tree: MatTree<TestData>;
965+
@ViewChild(MatTree) tree!: MatTree<TestData>;
966966

967967
constructor() {
968968
this.underlyingDataSource.connect().subscribe(data => {
@@ -1003,7 +1003,7 @@ class WhenNodeNestedMatTreeApp {
10031003
dataSource = new MatTreeNestedDataSource<TestData>();
10041004
underlyingDataSource = new FakeDataSource();
10051005

1006-
@ViewChild(MatTree) tree: MatTree<TestData>;
1006+
@ViewChild(MatTree) tree!: MatTree<TestData>;
10071007

10081008
constructor() {
10091009
this.underlyingDataSource.connect().subscribe(data => {
@@ -1034,7 +1034,7 @@ class MatTreeAppWithToggle {
10341034

10351035
dataSource: FakeDataSource = new FakeDataSource();
10361036

1037-
@ViewChild(MatTree) tree: MatTree<TestData>;
1037+
@ViewChild(MatTree) tree!: MatTree<TestData>;
10381038
}
10391039

10401040
@Component({
@@ -1068,7 +1068,7 @@ class NestedMatTreeAppWithToggle {
10681068

10691069
dataSource = new FakeDataSource();
10701070

1071-
@ViewChild(MatTree) tree: MatTree<TestData>;
1071+
@ViewChild(MatTree) tree!: MatTree<TestData>;
10721072
}
10731073

10741074
@Component({
@@ -1096,5 +1096,5 @@ class WhenNodeMatTreeApp {
10961096

10971097
dataSource = new FakeDataSource();
10981098

1099-
@ViewChild(MatTree) tree: MatTree<TestData>;
1099+
@ViewChild(MatTree) tree!: MatTree<TestData>;
11001100
}

src/material/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"compilerOptions": {
55
"rootDirs": ["..", "../../tools"],
66
"baseUrl": ".",
7+
"strictPropertyInitialization": true,
78
"paths": {
89
"@angular/cdk": ["../cdk"],
910
"@angular/cdk/*": ["../cdk/*"],

0 commit comments

Comments
 (0)