Skip to content

fix(material/datepicker): Return union of view component types #23000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/material/datepicker/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,18 +385,7 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes

/** Updates today's date after an update of the active date */
updateTodaysDate() {
const currentView = this.currentView;
let view: MatMonthView<D> | MatYearView<D> | MatMultiYearView<D>;

if (currentView === 'month') {
view = this.monthView;
} else if (currentView === 'year') {
view = this.yearView;
} else {
view = this.multiYearView;
}

view._init();
this._getCurrentViewComponent()._init();
}

/** Handles date selection in the month view. */
Expand Down Expand Up @@ -428,7 +417,10 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
}

/** Returns the component instance that corresponds to the current calendar view. */
private _getCurrentViewComponent() {
private _getCurrentViewComponent(): MatMonthView<D> | MatYearView<D> | MatMultiYearView<D> {
// The return type is explicitly written as a union to ensure that the Closure compiler does
// not optimize calls to _init(). Without the explict return type, TypeScript narrows it to
// only the first component type. See https://github.com/angular/components/issues/22996.
return this.monthView || this.yearView || this.multiYearView;
}
}