Skip to content

Commit 142ee5a

Browse files
committed
build: material components should be built with strict type checking
1 parent eb9a47e commit 142ee5a

File tree

10 files changed

+43
-27
lines changed

10 files changed

+43
-27
lines changed

src/cdk/stepper/stepper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
254254
@ContentChildren(CdkStep) _steps: QueryList<CdkStep>;
255255

256256
/** The list of step components that the stepper is holding. */
257-
get steps(): QueryList<CdkStep> {
257+
get steps(): QueryList<CdkStep> {
258+
// Note that the query list cannot be used in the template as iterable
259+
// because it breaks Ivy's strict template type checking. Therefore the
260+
// template currently uses "steps.toArray()". Read more about this:
261+
// https://github.com/angular/angular/issues/29842
258262
return this._steps;
259263
}
260264

src/material/button-toggle/button-toggle.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[id]="buttonId"
44
[attr.tabindex]="disabled ? -1 : tabIndex"
55
[attr.aria-pressed]="checked"
6-
[disabled]="disabled || null"
6+
[disabled]="disabled"
77
[attr.name]="name || null"
88
[attr.aria-label]="ariaLabel"
99
[attr.aria-labelledby]="ariaLabelledby"

src/material/core/option/option.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<mat-pseudo-checkbox *ngIf="multiple" class="mat-option-pseudo-checkbox"
2-
[state]="selected ? 'checked' : ''" [disabled]="disabled"></mat-pseudo-checkbox>
2+
[state]="selected ? 'checked' : 'unchecked'" [disabled]="disabled"></mat-pseudo-checkbox>
33

44
<span class="mat-option-text"><ng-content></ng-content></span>
55

src/material/datepicker/calendar-body.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {take} from 'rxjs/operators';
2323
/**
2424
* Extra CSS classes that can be associated with a calendar cell.
2525
*/
26-
export type MatCalendarCellCssClasses = string | string[] | Set<string> | {[key: string]: any};
26+
export type MatCalendarCellCssClasses = string | string[] | Set<string> | {[key: string]: any}
27+
| undefined;
2728

2829
/**
2930
* An internal class that represents the data corresponding to a single calendar cell.
@@ -63,11 +64,17 @@ export class MatCalendarBody implements OnChanges {
6364
/** The cells to display in the table. */
6465
@Input() rows: MatCalendarCell[][];
6566

66-
/** The value in the table that corresponds to today. */
67-
@Input() todayValue: number;
67+
/**
68+
* The value in the table that corresponds to today. Can be set to null if no
69+
* cell in the table corresponds to today.
70+
*/
71+
@Input() todayValue: number|null;
6872

69-
/** The value in the table that is currently selected. */
70-
@Input() selectedValue: number;
73+
/**
74+
* The value in the table that is currently selected. Null if no cell in the
75+
* table is selected.
76+
*/
77+
@Input() selectedValue: number|null;
7178

7279
/** The minimum number of free cells needed to fit the label in the first row. */
7380
@Input() labelMinRequiredCells: number;

src/material/datepicker/year-view.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<tbody mat-calendar-body
66
[label]="_yearLabel"
77
[rows]="_months"
8-
[todayValue]="_todayMonth"
9-
[selectedValue]="_selectedMonth"
8+
[todayValue]="_todayMonth!"
9+
[selectedValue]="_selectedMonth!"
1010
[labelMinRequiredCells]="2"
1111
[numCols]="4"
1212
[cellAspectRatio]="4 / 7"

src/material/select/select.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import {
2222
UP_ARROW,
2323
hasModifierKey,
2424
} from '@angular/cdk/keycodes';
25-
import {CdkConnectedOverlay, Overlay, ScrollStrategy} from '@angular/cdk/overlay';
25+
import {
26+
CdkConnectedOverlay,
27+
ConnectedPosition,
28+
Overlay,
29+
ScrollStrategy
30+
} from '@angular/cdk/overlay';
2631
import {ViewportRuler} from '@angular/cdk/scrolling';
2732
import {
2833
AfterContentInit,
@@ -299,7 +304,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
299304
* the trigger completely). If the panel cannot fit below the trigger, it
300305
* will fall back to a position above the trigger.
301306
*/
302-
_positions = [
307+
_positions: ConnectedPosition[] = [
303308
{
304309
originX: 'start',
305310
originY: 'top',

src/material/stepper/stepper-horizontal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="mat-horizontal-stepper-header-container">
2-
<ng-container *ngFor="let step of steps; let i = index; let isLast = last">
2+
<ng-container *ngFor="let step of steps.toArray(); let i = index; let isLast = last">
33
<mat-step-header class="mat-horizontal-stepper-header"
44
(click)="step.select()"
55
(keydown)="_onKeydown($event)"
@@ -26,7 +26,7 @@
2626
</div>
2727

2828
<div class="mat-horizontal-content-container">
29-
<div *ngFor="let step of steps; let i = index"
29+
<div *ngFor="let step of steps.toArray(); let i = index"
3030
[attr.tabindex]="selectedIndex === i ? 0 : null"
3131
class="mat-horizontal-stepper-content" role="tabpanel"
3232
[@stepTransition]="_getAnimationDirection(i)"

src/material/stepper/stepper-vertical.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="mat-step" *ngFor="let step of steps; let i = index; let isLast = last">
1+
<div class="mat-step" *ngFor="let step of steps.toArray(); let i = index; let isLast = last">
22
<mat-step-header class="mat-vertical-stepper-header"
33
(click)="step.select()"
44
(keydown)="_onKeydown($event)"

src/material/tabs/tab-body.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class MatTabBody implements OnInit, OnDestroy {
147147
@Input('content') _content: TemplatePortal;
148148

149149
/** Position that will be used when the tab is immediately becoming visible after creation. */
150-
@Input() origin: number;
150+
@Input() origin: number|null;
151151

152152
// Note that the default value will always be overwritten by `MatTabBody`, but we need one
153153
// anyway to prevent the animations module from throwing an error if the body is used on its own.
@@ -194,7 +194,7 @@ export class MatTabBody implements OnInit, OnDestroy {
194194
*/
195195
ngOnInit() {
196196
if (this._position == 'center' && this.origin != null) {
197-
this._position = this._computePositionFromOrigin();
197+
this._position = this._computePositionFromOrigin(this.origin);
198198
}
199199
}
200200

@@ -238,10 +238,10 @@ export class MatTabBody implements OnInit, OnDestroy {
238238
* Computes the position state based on the specified origin position. This is used if the
239239
* tab is becoming visible immediately after creation.
240240
*/
241-
private _computePositionFromOrigin(): MatTabBodyPositionState {
241+
private _computePositionFromOrigin(origin: number): MatTabBodyPositionState {
242242
const dir = this._getLayoutDirection();
243243

244-
if ((dir == 'ltr' && this.origin <= 0) || (dir == 'rtl' && this.origin > 0)) {
244+
if ((dir == 'ltr' && origin <= 0) || (dir == 'rtl' && origin > 0)) {
245245
return 'left-origin-center';
246246
}
247247

src/material/tabs/tab-group.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<mat-tab-header #tabHeader
2-
[selectedIndex]="selectedIndex"
3-
[disableRipple]="disableRipple"
4-
(indexFocused)="_focusChanged($event)"
5-
(selectFocusedIndex)="selectedIndex = $event">
2+
[selectedIndex]="selectedIndex || 0"
3+
[disableRipple]="disableRipple"
4+
(indexFocused)="_focusChanged($event)"
5+
(selectFocusedIndex)="selectedIndex = $event">
66
<div class="mat-tab-label" role="tab" matTabLabelWrapper mat-ripple cdkMonitorElementFocus
7-
*ngFor="let tab of _tabs; let i = index"
7+
*ngFor="let tab of _tabs.toArray(); let i = index"
88
[id]="_getTabLabelId(i)"
99
[attr.tabIndex]="_getTabIndex(tab, i)"
1010
[attr.aria-posinset]="i + 1"
@@ -36,12 +36,12 @@
3636
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
3737
#tabBodyWrapper>
3838
<mat-tab-body role="tabpanel"
39-
*ngFor="let tab of _tabs; let i = index"
39+
*ngFor="let tab of _tabs.toArray(); let i = index"
4040
[id]="_getTabContentId(i)"
4141
[attr.aria-labelledby]="_getTabLabelId(i)"
4242
[class.mat-tab-body-active]="selectedIndex == i"
43-
[content]="tab.content"
44-
[position]="tab.position"
43+
[content]="tab.content!"
44+
[position]="tab.position!"
4545
[origin]="tab.origin"
4646
[animationDuration]="animationDuration"
4747
(_onCentered)="_removeTabBodyWrapperHeight()"

0 commit comments

Comments
 (0)