Skip to content

Commit 7f71feb

Browse files
committed
fix(material/tabs): Remove any type
1 parent deb77e2 commit 7f71feb

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

src/material/tabs/tab-body.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class SimpleTabBodyApp implements AfterViewInit {
146146
position: number;
147147

148148
@ViewChild(MatTabBody) tabBody: MatTabBody;
149-
@ViewChild(TemplateRef) template: TemplateRef<any>;
149+
@ViewChild(TemplateRef) template: TemplateRef<unknown>;
150150

151151
private readonly _viewContainerRef = inject(ViewContainerRef);
152152

src/material/tabs/tab-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const MAT_TAB_CONTENT = new InjectionToken<MatTabContent>('MatTabContent'
2121
providers: [{provide: MAT_TAB_CONTENT, useExisting: MatTabContent}],
2222
})
2323
export class MatTabContent {
24-
template = inject<TemplateRef<any>>(TemplateRef);
24+
template = inject<TemplateRef<unknown>>(TemplateRef);
2525

2626
constructor(...args: unknown[]);
2727
constructor() {}

src/material/tabs/tab-group.spec.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import {
1111
waitForAsync,
1212
} from '@angular/core/testing';
1313
import {By} from '@angular/platform-browser';
14-
import {Observable} from 'rxjs';
14+
import {Observable, Subscriber} from 'rxjs';
1515
import {
1616
MAT_TABS_CONFIG,
1717
MatTab,
1818
MatTabGroup,
1919
MatTabHeader,
2020
MatTabHeaderPosition,
2121
MatTabsModule,
22+
MatTabChangeEvent,
2223
} from './index';
2324
import {MATERIAL_ANIMATIONS} from '../core';
2425

@@ -1028,7 +1029,7 @@ describe('MatTabGroup', () => {
10281029
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
10291030
* respective `active` classes
10301031
*/
1031-
function checkSelectedIndex(expectedIndex: number, fixture: ComponentFixture<any>) {
1032+
function checkSelectedIndex(expectedIndex: number, fixture: ComponentFixture<unknown>) {
10321033
fixture.detectChanges();
10331034

10341035
let tabComponent: MatTabGroup = fixture.debugElement.query(
@@ -1047,11 +1048,11 @@ describe('MatTabGroup', () => {
10471048
expect(tabContentElement.classList.contains('mat-mdc-tab-body-active')).toBe(true);
10481049
}
10491050

1050-
function getSelectedLabel(fixture: ComponentFixture<any>): HTMLElement {
1051+
function getSelectedLabel(fixture: ComponentFixture<unknown>): HTMLElement {
10511052
return fixture.nativeElement.querySelector('.mdc-tab--active');
10521053
}
10531054

1054-
function getSelectedContent(fixture: ComponentFixture<any>): HTMLElement {
1055+
function getSelectedContent(fixture: ComponentFixture<unknown>): HTMLElement {
10551056
return fixture.nativeElement.querySelector('.mat-mdc-tab-body-active');
10561057
}
10571058
});
@@ -1285,18 +1286,18 @@ class SimpleTabsTestApp {
12851286
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
12861287
@ViewChildren(MatTab) tabs: QueryList<MatTab>;
12871288
selectedIndex: number = 1;
1288-
focusEvent: any;
1289-
selectEvent: any;
1289+
focusEvent: MatTabChangeEvent;
1290+
selectEvent: MatTabChangeEvent;
12901291
disableRipple: boolean = false;
12911292
contentTabIndex: number | null = null;
12921293
headerPosition: MatTabHeaderPosition = 'above';
12931294
ariaLabel: string;
12941295
ariaLabelledby: string;
12951296
secondTabId: string | null = null;
1296-
handleFocus(event: any) {
1297+
handleFocus(event: MatTabChangeEvent) {
12971298
this.focusEvent = event;
12981299
}
1299-
handleSelection(event: any) {
1300+
handleSelection(event: MatTabChangeEvent) {
13001301
this.selectEvent = event;
13011302
}
13021303
animationDone() {}
@@ -1326,13 +1327,13 @@ class SimpleDynamicTabsTestApp {
13261327
{label: 'Label 3', content: 'Content 3'},
13271328
];
13281329
selectedIndex: number = 1;
1329-
focusEvent: any;
1330-
selectEvent: any;
1330+
focusEvent: MatTabChangeEvent;
1331+
selectEvent: MatTabChangeEvent;
13311332
disablePagination = false;
1332-
handleFocus(event: any) {
1333+
handleFocus(event: MatTabChangeEvent) {
13331334
this.focusEvent = event;
13341335
}
1335-
handleSelection(event: any) {
1336+
handleSelection(event: MatTabChangeEvent) {
13361337
this.selectEvent = event;
13371338
}
13381339
}
@@ -1406,11 +1407,11 @@ class AsyncTabsTestApp implements OnInit {
14061407
{label: 'two', content: 'two'},
14071408
];
14081409

1409-
tabs: Observable<any>;
1410+
tabs: Observable<typeof this._tabs>;
14101411

14111412
ngOnInit() {
14121413
// Use ngOnInit because there is some issue with scheduling the async task in the constructor.
1413-
this.tabs = new Observable((observer: any) => {
1414+
this.tabs = new Observable((observer: Subscriber<typeof this._tabs>) => {
14141415
setTimeout(() => observer.next(this._tabs));
14151416
});
14161417
}
@@ -1431,7 +1432,7 @@ class TabGroupWithSimpleApi {
14311432
preserveContent = false;
14321433
otherLabel = 'Fruit';
14331434
otherContent = 'Apples, grapes';
1434-
@ViewChild('legumes') legumes: any;
1435+
@ViewChild('legumes') legumes: HTMLParagraphElement;
14351436
}
14361437

14371438
@Component({

src/material/tabs/tab-header.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ describe('MatTabHeader', () => {
699699
spyOn(TestBed.inject(MutationObserverFactory), 'create').and.callFake(
700700
(callback: Function) => {
701701
mutationCallbacks.push(callback);
702-
return {observe: () => {}, disconnect: () => {}} as any;
702+
return {observe: () => {}, disconnect: () => {}} as unknown as MutationObserver;
703703
},
704704
);
705705

src/material/tabs/tab-label.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {Directive, InjectionToken, inject} from '@angular/core';
1010
import {CdkPortal} from '@angular/cdk/portal';
11+
import {type MatTab} from './tab';
1112

1213
/**
1314
* Injection token that can be used to reference instances of `MatTabLabel`. It serves as
@@ -20,7 +21,7 @@ export const MAT_TAB_LABEL = new InjectionToken<MatTabLabel>('MatTabLabel');
2021
* Used to provide a tab label to a tab without causing a circular dependency.
2122
* @docs-private
2223
*/
23-
export const MAT_TAB = new InjectionToken<any>('MAT_TAB');
24+
export const MAT_TAB = new InjectionToken<MatTab>('MAT_TAB');
2425

2526
/** Used to flag tab labels for use with the portal directive */
2627
@Directive({

src/material/tabs/tab.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ import {TemplatePortal} from '@angular/cdk/portal';
2929
import {Subject} from 'rxjs';
3030
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
3131
import {_StructuralStylesLoader} from '../core';
32+
import {type MatTabGroup} from './tab-group';
3233

3334
/**
3435
* Used to provide a tab group to a tab without causing a circular dependency.
3536
* @docs-private
3637
*/
37-
export const MAT_TAB_GROUP = new InjectionToken<any>('MAT_TAB_GROUP');
38+
export const MAT_TAB_GROUP = new InjectionToken<MatTabGroup>('MAT_TAB_GROUP');
3839

3940
@Component({
4041
selector: 'mat-tab',
@@ -78,11 +79,11 @@ export class MatTab implements OnInit, OnChanges, OnDestroy {
7879
* Template provided in the tab content that will be used if present, used to enable lazy-loading
7980
*/
8081
@ContentChild(MatTabContent, {read: TemplateRef, static: true})
81-
// We need an initializer here to avoid a TS error. The value will be set in `ngAfterViewInit`.
82-
private _explicitContent: TemplateRef<any> = undefined!;
82+
// The value will be set in `ngAfterViewInit`.
83+
private _explicitContent?: TemplateRef<unknown>;
8384

8485
/** Template inside the MatTab view that contains an `<ng-content>`. */
85-
@ViewChild(TemplateRef, {static: true}) _implicitContent: TemplateRef<any>;
86+
@ViewChild(TemplateRef, {static: true}) _implicitContent: TemplateRef<unknown>;
8687

8788
/** Plain text label for the tab, used when there is no template label. */
8889
@Input('label') textLabel: string = '';

0 commit comments

Comments
 (0)