Skip to content

Commit 09b51ec

Browse files
committed
fix(material/tabs): Remove any type
1 parent 4206c69 commit 09b51ec

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
@@ -160,7 +160,7 @@ class SimpleTabBodyApp implements AfterViewInit {
160160
position: number;
161161

162162
@ViewChild(MatTabBody) tabBody: MatTabBody;
163-
@ViewChild(TemplateRef) template: TemplateRef<any>;
163+
@ViewChild(TemplateRef) template: TemplateRef<unknown>;
164164

165165
private readonly _viewContainerRef = inject(ViewContainerRef);
166166

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
@@ -12,14 +12,15 @@ import {
1212
} from '@angular/core/testing';
1313
import {By} from '@angular/platform-browser';
1414
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
15-
import {Observable} from 'rxjs';
15+
import {Observable, Subscriber} from 'rxjs';
1616
import {
1717
MAT_TABS_CONFIG,
1818
MatTab,
1919
MatTabGroup,
2020
MatTabHeader,
2121
MatTabHeaderPosition,
2222
MatTabsModule,
23+
MatTabChangeEvent,
2324
} from './index';
2425

2526
describe('MatTabGroup', () => {
@@ -1034,7 +1035,7 @@ describe('MatTabGroup', () => {
10341035
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
10351036
* respective `active` classes
10361037
*/
1037-
function checkSelectedIndex(expectedIndex: number, fixture: ComponentFixture<any>) {
1038+
function checkSelectedIndex(expectedIndex: number, fixture: ComponentFixture<unknown>) {
10381039
fixture.detectChanges();
10391040

10401041
let tabComponent: MatTabGroup = fixture.debugElement.query(
@@ -1053,11 +1054,11 @@ describe('MatTabGroup', () => {
10531054
expect(tabContentElement.classList.contains('mat-mdc-tab-body-active')).toBe(true);
10541055
}
10551056

1056-
function getSelectedLabel(fixture: ComponentFixture<any>): HTMLElement {
1057+
function getSelectedLabel(fixture: ComponentFixture<unknown>): HTMLElement {
10571058
return fixture.nativeElement.querySelector('.mdc-tab--active');
10581059
}
10591060

1060-
function getSelectedContent(fixture: ComponentFixture<any>): HTMLElement {
1061+
function getSelectedContent(fixture: ComponentFixture<unknown>): HTMLElement {
10611062
return fixture.nativeElement.querySelector('.mat-mdc-tab-body-active');
10621063
}
10631064
});
@@ -1291,18 +1292,18 @@ class SimpleTabsTestApp {
12911292
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
12921293
@ViewChildren(MatTab) tabs: QueryList<MatTab>;
12931294
selectedIndex: number = 1;
1294-
focusEvent: any;
1295-
selectEvent: any;
1295+
focusEvent: MatTabChangeEvent;
1296+
selectEvent: MatTabChangeEvent;
12961297
disableRipple: boolean = false;
12971298
contentTabIndex: number | null = null;
12981299
headerPosition: MatTabHeaderPosition = 'above';
12991300
ariaLabel: string;
13001301
ariaLabelledby: string;
13011302
secondTabId: string | null = null;
1302-
handleFocus(event: any) {
1303+
handleFocus(event: MatTabChangeEvent) {
13031304
this.focusEvent = event;
13041305
}
1305-
handleSelection(event: any) {
1306+
handleSelection(event: MatTabChangeEvent) {
13061307
this.selectEvent = event;
13071308
}
13081309
animationDone() {}
@@ -1332,13 +1333,13 @@ class SimpleDynamicTabsTestApp {
13321333
{label: 'Label 3', content: 'Content 3'},
13331334
];
13341335
selectedIndex: number = 1;
1335-
focusEvent: any;
1336-
selectEvent: any;
1336+
focusEvent: MatTabChangeEvent;
1337+
selectEvent: MatTabChangeEvent;
13371338
disablePagination = false;
1338-
handleFocus(event: any) {
1339+
handleFocus(event: MatTabChangeEvent) {
13391340
this.focusEvent = event;
13401341
}
1341-
handleSelection(event: any) {
1342+
handleSelection(event: MatTabChangeEvent) {
13421343
this.selectEvent = event;
13431344
}
13441345
}
@@ -1412,11 +1413,11 @@ class AsyncTabsTestApp implements OnInit {
14121413
{label: 'two', content: 'two'},
14131414
];
14141415

1415-
tabs: Observable<any>;
1416+
tabs: Observable<typeof this._tabs>;
14161417

14171418
ngOnInit() {
14181419
// Use ngOnInit because there is some issue with scheduling the async task in the constructor.
1419-
this.tabs = new Observable((observer: any) => {
1420+
this.tabs = new Observable((observer: Subscriber<typeof this._tabs>) => {
14201421
setTimeout(() => observer.next(this._tabs));
14211422
});
14221423
}
@@ -1437,7 +1438,7 @@ class TabGroupWithSimpleApi {
14371438
preserveContent = false;
14381439
otherLabel = 'Fruit';
14391440
otherContent = 'Apples, grapes';
1440-
@ViewChild('legumes') legumes: any;
1441+
@ViewChild('legumes') legumes: HTMLParagraphElement;
14411442
}
14421443

14431444
@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)