Skip to content

bug(datepicker): mat-calendar ngOnChanges incorrectly optimized by Closure compiler #22996

Closed
@rslawik

Description

@rslawik

Reproduction

  1. Click on the mont-year button.
  2. Click on the year.
  3. Error is logged in the console.
  4. Click on the month.
  5. Another error logged.

The date picker calendar has code like:

const view = this._getCurrentViewComponent();
if (view) {
  view._init();
}

where the getCurrentViewComponent is:

private _getCurrentViewComponent() {
  return this.monthView || this.yearView || this.multiYearView;
}

Each view is a non-null property on the class, so TypeScript infers that the return type is typeof this.monthView and tsickle propagates that to calendar.closure.js. Then the JavaScript compiler assumes that view._init call is always the function from monthView and optimizes code to only that.

Expected Behavior

No errors.

Actual Behavior

Errors are logged to the console:

  • RangeError: Invalid time value
  • TypeError: a.v is not a function

Environment

  • Angular: n/a
  • CDK/Material: n/a
  • Browser(s): n/a
  • Operating System (e.g. Windows, macOS, Ubuntu): n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/datepicker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions