tabs(ivy): ivy-ngcc can't handle Inputs from an abstract class w/o a decorator like _MatTabGroupBase
Hi,
I am getting this error after upgrade in current cli in mat-tab-group.
Property 'selectedIndex' does not exist on type 'HTMLElement'
Example picking from Angular Website and run after the upgrade to latest then getting this error previously it was not giving any error. HTML Code is -
<mat-tab-group [selectedIndex]="selected.value"
(selectedIndexChange)="selected.setValue($event)">
<mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
Contents for {{tab}} tab
<button mat-raised-button
class="example-delete-tab-button"
[disabled]="tabs.length === 1"
(click)="removeTab(index)">
Delete Tab
</button>
</mat-tab>
</mat-tab-group>
Component Code is-
import {Component} from '@angular/core';
import {FormControl} from '@angular/forms';
/**
* @title Tab group with dynamically changing tabs
*/
@Component({
selector: 'tab-group-dynamic-example',
templateUrl: 'tab-group-dynamic-example.html',
styleUrls: ['tab-group-dynamic-example.css'],
})
export class TabGroupDynamicExample {
tabs = ['First', 'Second', 'Third'];
selected = new FormControl(0);
addTab(selectAfterAdding: boolean) {
this.tabs.push('New');
if (selectAfterAdding) {
this.selected.setValue(this.tabs.length - 1);
}
}
removeTab(index: number) {
this.tabs.splice(index, 1);
}
}
Package.json is
{
"name": "WFXERPAg",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^8.2.6",
"@angular/cdk": "^8.2.0",
"@angular/common": "~8.2.6",
"@angular/compiler": "~8.2.6",
"@angular/core": "~8.2.6",
"@angular/forms": "~8.2.6",
"@angular/material": "^8.2.0",
"@angular/material-moment-adapter": "^8.2.0",
"@angular/platform-browser": "~8.2.6",
"@angular/platform-browser-dynamic": "~8.2.6",
"@angular/router": "~8.2.6",
"core-js": "^3.1.4",
"jquery": "^3.4.0",
"jquery-ui": "^1.12.1",
"jquery-ui-dist": "^1.12.1",
"moment": "^2.24.0",
"rxjs": "~6.5.3",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.0",
"@angular/cli": "~8.3.4",
"@angular/compiler-cli": "~8.2.6",
"@angular/language-service": "~8.2.6",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^8.9.5",
"codelyzer": "^5.0.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "^5.20.0",
"typescript": "~3.5.3"
}
}
If this is the only command ng update @angular/cli @angular/core then i ran this command so many times after v7. I check daily basis of any update is coming in my project. But yeah it's a silly mistake. What I am doing now is I'll update ng update @angular/cli globally and then I'll create a new project and then copy all of my files into that project. This will be correct right?
@ErVishalM what you can do is ng update @angular/cli --migrate-only --from=7 --to=8 and it will try to re-run any migration schematics. Some of the very early 8.0.0 versions didn't include the full set of migrations needed.
As for debugging this issue, none of the mat-tab-group Inputs show up in the ngComponentDef generated from ngcc:
static ngComponentDef: ɵngcc0.ɵɵComponentDefWithMeta<MatTabGroup, "mat-tab-group", ["matTabGroup"], { 'color': "color", 'disableRipple': "disableRipple" }, {}, ["_tabs"]>;
So this looks like an issue with ngcc.
The associated ngcc bugs appear to be
- https://github.com/angular/angular/issues/32895
- https://github.com/angular/angular/issues/32506
There also appear to be some related errors mentioned in https://github.com/angular/angular/issues/32466#issuecomment-530464310.
https://github.com/SebastianM/angular-google-maps/issues/1647#issuecomment-535804778 mentions that the issue could be related to the way that decorators are emitted.
@Splaktar I don't think those are indeed the cause for this issue, but rather it's https://github.com/angular/angular/issues/30080. The _MatTabGroupBase is an abstract base class without Angular decorator at the class-level, so currently it is compiled into an ngBaseDef which is not currently handled in the template type checker.
Originally it looked like ngcc was ignoring a bunch of @Inputs when they were associated with get/set methods.
https://github.com/angular/components/blob/492fdcc40b3cfcadd825c29ba9f505c6e5794a50/src/material/tabs/tab-group.ts#L99-L137
But now it is looking more like this could be due to MatTabGroup's @Inputs all coming from _MatTabGroupBase:
https://github.com/angular/components/blob/492fdcc40b3cfcadd825c29ba9f505c6e5794a50/src/material/tabs/tab-group.ts#L363
It looks like we need to add something similar to the following for each Abstract Base Class that includes any kind of Decorator:
@Directive({selector: 'mat-tab-group-base'})
We can't use empty selectors (i.e. @Directive()) since those are only supported in Angular 9.0.0-next.3.
Angular Flex Layout had to do something similar in https://github.com/angular/flex-layout/pull/1114 for Ivy support.
Ideally, this would be fixed in ivy-ngcc as this shouldn't be a breaking change to all libraries at final... I hope.
Adding that causes the following build error:
Cannot determine the module for class _MatTabGroupBase in /Users/splaktar/Git/angular/material2/src/material/tabs/tab-group.ts! Add _MatTabGroupBase to the NgModule to fix it.
Adding that to MatTabsModule
declarations: [
_MatTabGroupBase,
Causes this build error:
tabs-module.ts(26,11): error TS2345: Argument of type '{ imports: (typeof CommonModule | typeof MatCommonModule)[]; exports: (typeof MatTabContent | typeof MatTabLabel | typeof MatTab | typeof MatTabGroup | typeof MatTabNav | typeof MatTabLink | typeof MatCommonModule)[]; declarations: (typeof MatTabContent | ... 9 more ... | typeof MatTabHeader)[]; }' is not assignable to parameter of type 'NgModule'.
Types of property 'declarations' are incompatible.
Type '(typeof MatTabContent | typeof MatTabLabel | typeof MatTab | typeof _MatTabGroupBase | typeof MatInkBar | typeof MatTabLabelWrapper | typeof MatTabNav | typeof MatTabLink | typeof MatTabBodyPortal | typeof MatTabBody | typeof MatTabHeader)[]' is not assignable to type '(any[] | Type<any>)[]'.
Type 'typeof MatTabContent | typeof MatTabLabel | typeof MatTab | typeof _MatTabGroupBase | typeof MatInkBar | typeof MatTabLabelWrapper | typeof MatTabNav | typeof MatTabLink | typeof MatTabBodyPortal | typeof MatTabBody | typeof MatTabHeader' is not assignable to type 'any[] | Type<any>'.
Type 'typeof _MatTabGroupBase' is not assignable to type 'any[] | Type<any>'.
Type 'typeof _MatTabGroupBase' is not assignable to type 'Type<any>'.
Cannot assign an abstract constructor type to a non-abstract constructor type.
@crisbeto @Splaktar will be this fix only for Angular 9 Next available or do you guys will deploy this fix also for Angular 8.x.x (Ivy Enabled)?
Based on PR https://github.com/angular/components/pull/17022 and PR https://github.com/angular/components/pull/17228, it looks like you would actually need to either
- create a whole new
_MatTabGroupBaseModuleto get this to compile - add them to
declarationsasanylike_MatTabGroupBase as any,
It also looks like @jelbourn wants these module and selector names prepended with DoNotUse or do-not-use.
It looks like the combination of those 2 PRs should fix these issues for Angular Material w/ Ivy.
@SerkanSipahi I believe that this can be fixed in Angular Material 8.2.x.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.