Skip to content

Commit a402b5e

Browse files
committed
build: make material-examples compatible with ivy template type checking
1 parent 99a96d5 commit a402b5e

File tree

17 files changed

+39
-22
lines changed

17 files changed

+39
-22
lines changed

src/material-examples/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-form-field class="example-full-width">
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
5-
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
5+
<mat-option *ngFor="let option of (filteredOptions | async)!" [value]="option">
66
{{option}}
77
</mat-option>
88
</mat-autocomplete>

src/material-examples/autocomplete-display/autocomplete-display-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-form-field class="example-full-width">
33
<input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
5-
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
5+
<mat-option *ngFor="let option of (filteredOptions | async)!" [value]="option">
66
{{option.name}}
77
</mat-option>
88
</mat-autocomplete>

src/material-examples/autocomplete-display/autocomplete-display-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export class AutocompleteDisplayExample implements OnInit {
3333
);
3434
}
3535

36-
displayFn(user?: User): string | undefined {
37-
return user ? user.name : undefined;
36+
displayFn(user: User): string {
37+
return user.name;
3838
}
3939

4040
private _filter(name: string): User[] {

src/material-examples/autocomplete-filter/autocomplete-filter-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-form-field class="example-full-width">
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete">
5-
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
5+
<mat-option *ngFor="let option of (filteredOptions | async)!" [value]="option">
66
{{option}}
77
</mat-option>
88
</mat-autocomplete>

src/material-examples/autocomplete-optgroup/autocomplete-optgroup-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-form-field>
33
<input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup">
44
<mat-autocomplete #autoGroup="matAutocomplete">
5-
<mat-optgroup *ngFor="let group of stateGroupOptions | async" [label]="group.letter">
5+
<mat-optgroup *ngFor="let group of (stateGroupOptions | async)!" [label]="group.letter">
66
<mat-option *ngFor="let name of group.names" [value]="name">
77
{{name}}
88
</mat-option>

src/material-examples/autocomplete-overview/autocomplete-overview-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-form-field class="example-full-width">
33
<input matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
44
<mat-autocomplete #auto="matAutocomplete">
5-
<mat-option *ngFor="let state of filteredStates | async" [value]="state.name">
5+
<mat-option *ngFor="let state of (filteredStates | async)!" [value]="state.name">
66
<img class="example-option-img" aria-hidden [src]="state.flag" height="25">
77
<span>{{state.name}}</span> |
88
<small>Population: {{state.population}}</small>

src/material-examples/autocomplete-plain-input/autocomplete-plain-input-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<form class="example-form">
22
<input type="text" placeholder="Search for a street" [formControl]="control" [matAutocomplete]="auto">
33
<mat-autocomplete #auto="matAutocomplete">
4-
<mat-option *ngFor="let street of filteredStreets | async" [value]="street">
4+
<mat-option *ngFor="let street of (filteredStreets | async)!" [value]="street">
55
{{street}}
66
</mat-option>
77
</mat-autocomplete>

src/material-examples/cdk-custom-stepper-without-form/example-custom-stepper.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2>Step {{ selectedIndex + 1 }}/{{ steps.length }}</h2>
1111
<button class="example-nav-button" cdkStepperPrevious>&larr;</button>
1212
<button
1313
class="example-step"
14-
*ngFor="let step of steps; let i = index"
14+
*ngFor="let step of steps.toArray(); let i = index"
1515
[ngClass]="{ 'example-active': selectedIndex === i }"
1616
(click)="onClick(i)"
1717
>

src/material-examples/checkbox-configurable/checkbox-configurable-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import {Component} from '@angular/core';
1111
export class CheckboxConfigurableExample {
1212
checked = false;
1313
indeterminate = false;
14-
labelPosition = 'after';
14+
labelPosition: 'after'|'before' = 'after';
1515
disabled = false;
1616
}

src/material-examples/chips-autocomplete/chips-autocomplete-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
(matChipInputTokenEnd)="add($event)">
2020
</mat-chip-list>
2121
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
22-
<mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
22+
<mat-option *ngFor="let fruit of (filteredFruits | async)!" [value]="fruit">
2323
{{fruit}}
2424
</mat-option>
2525
</mat-autocomplete>

src/material-examples/progress-bar-configurable/progress-bar-configurable-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component} from '@angular/core';
2+
import {ThemePalette} from '@angular/material/core';
23

34
/**
45
* @title Configurable progress-bar
@@ -9,8 +10,8 @@ import {Component} from '@angular/core';
910
styleUrls: ['progress-bar-configurable-example.css'],
1011
})
1112
export class ProgressBarConfigurableExample {
12-
color = 'primary';
13-
mode = 'determinate';
13+
color: ThemePalette = 'primary';
14+
mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate';
1415
value = 50;
1516
bufferValue = 75;
1617
}

src/material-examples/progress-spinner-configurable/progress-spinner-configurable-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component} from '@angular/core';
2+
import {ThemePalette} from '@angular/material/core';
23

34
/**
45
* @title Configurable progress spinner
@@ -9,7 +10,7 @@ import {Component} from '@angular/core';
910
styleUrls: ['progress-spinner-configurable-example.css'],
1011
})
1112
export class ProgressSpinnerConfigurableExample {
12-
color = 'primary';
13-
mode = 'determinate';
13+
color: ThemePalette = 'primary';
14+
mode: 'determinate' | 'indeterminate' = 'determinate';
1415
value = 50;
1516
}

src/material-examples/slide-toggle-configurable/slide-toggle-configurable-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component} from '@angular/core';
2+
import {ThemePalette} from '@angular/material/core';
23

34
/**
45
* @title Configurable slide-toggle
@@ -9,7 +10,7 @@ import {Component} from '@angular/core';
910
styleUrls: ['slide-toggle-configurable-example.css'],
1011
})
1112
export class SlideToggleConfigurableExample {
12-
color = 'accent';
13+
color: ThemePalette = 'accent';
1314
checked = false;
1415
disabled = false;
1516
}

src/material-examples/tab-group-async/tab-group-async-example.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
</ng-container>
44

55
<mat-tab-group>
6-
<mat-tab *ngFor="let tab of asyncTabs | async">
6+
<!--
7+
8+
TODO for review: In that case it's quite weird because with the async pipe
9+
the expression can evaluate to "null". The "[ngForOf]" input type does not accept
10+
"null" so it fails the strict Ivy template check... At runtime it works because
11+
there is a simple "truthy" check in the NgForOf directive... but the current
12+
type is incompatible and seems like it can become a general impacting issue with Ivy.
13+
14+
For reference: there are issues for the async pipe which could also return "undefined".
15+
See: https://github.com/angular/angular/issues/16982
16+
-->
17+
<mat-tab *ngFor="let tab of (asyncTabs | async)!">
718
<ng-template mat-tab-label>{{tab.label}}</ng-template>
819
{{tab.content}}
920
</mat-tab>

src/material-examples/tab-nav-bar-basic/tab-nav-bar-basic-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component} from '@angular/core';
2+
import {ThemePalette} from '@angular/material/core';
23

34
/**
45
* @title Basic use of the tab nav bar
@@ -11,9 +12,9 @@ import {Component} from '@angular/core';
1112
export class TabNavBarBasicExample {
1213
links = ['First', 'Second', 'Third'];
1314
activeLink = this.links[0];
14-
background = '';
15+
background: ThemePalette = undefined;
1516

1617
toggleBackground() {
17-
this.background = this.background ? '' : 'primary';
18+
this.background = this.background ? undefined : 'primary';
1819
}
1920
}

src/material-examples/table-text-column-advanced/table-text-column-advanced-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ export class TableTextColumnAdvancedExample {
3939
decimalPipe = new DecimalPipe('en-US');
4040

4141
/** Data accessor function that transforms the weight value to have at most 2 decimal digits. */
42-
getWeight = (data: PeriodicElement) => this.decimalPipe.transform(data.weight, '1.0-2');
42+
getWeight = (data: PeriodicElement) => this.decimalPipe.transform(data.weight, '1.0-2')!;
4343
}

src/material-examples/tree-dynamic/tree-dynamic-example.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CollectionViewer, SelectionChange} from '@angular/cdk/collections';
1+
import {CollectionViewer, DataSource, SelectionChange} from '@angular/cdk/collections';
22
import {FlatTreeControl} from '@angular/cdk/tree';
33
import {Component, Injectable} from '@angular/core';
44
import {BehaviorSubject, merge, Observable} from 'rxjs';
@@ -45,7 +45,7 @@ export class DynamicDatabase {
4545
* structure.
4646
*/
4747
@Injectable()
48-
export class DynamicDataSource {
48+
export class DynamicDataSource implements DataSource<DynamicFlatNode> {
4949

5050
dataChange = new BehaviorSubject<DynamicFlatNode[]>([]);
5151

@@ -69,6 +69,8 @@ export class DynamicDataSource {
6969
return merge(collectionViewer.viewChange, this.dataChange).pipe(map(() => this.data));
7070
}
7171

72+
disconnect(): void {}
73+
7274
/** Handle expand/collapse behaviors */
7375
handleTreeControl(change: SelectionChange<DynamicFlatNode>) {
7476
if (change.added) {

0 commit comments

Comments
 (0)