Skip to content

Commit 20bf6f7

Browse files
committed
fix(material/tabs): Remove any type
1 parent 06ed27d commit 20bf6f7

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', () => {
@@ -995,7 +996,7 @@ describe('MatTabGroup', () => {
995996
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
996997
* respective `active` classes
997998
*/
998-
function checkSelectedIndex(expectedIndex: number, fixture: ComponentFixture<any>) {
999+
function checkSelectedIndex(expectedIndex: number, fixture: ComponentFixture<unknown>) {
9991000
fixture.detectChanges();
10001001

10011002
let tabComponent: MatTabGroup = fixture.debugElement.query(
@@ -1014,11 +1015,11 @@ describe('MatTabGroup', () => {
10141015
expect(tabContentElement.classList.contains('mat-mdc-tab-body-active')).toBe(true);
10151016
}
10161017

1017-
function getSelectedLabel(fixture: ComponentFixture<any>): HTMLElement {
1018+
function getSelectedLabel(fixture: ComponentFixture<unknown>): HTMLElement {
10181019
return fixture.nativeElement.querySelector('.mdc-tab--active');
10191020
}
10201021

1021-
function getSelectedContent(fixture: ComponentFixture<any>): HTMLElement {
1022+
function getSelectedContent(fixture: ComponentFixture<unknown>): HTMLElement {
10221023
return fixture.nativeElement.querySelector('.mat-mdc-tab-body-active');
10231024
}
10241025
});
@@ -1252,17 +1253,17 @@ class SimpleTabsTestApp {
12521253
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
12531254
@ViewChildren(MatTab) tabs: QueryList<MatTab>;
12541255
selectedIndex: number = 1;
1255-
focusEvent: any;
1256-
selectEvent: any;
1256+
focusEvent: MatTabChangeEvent;
1257+
selectEvent: MatTabChangeEvent;
12571258
disableRipple: boolean = false;
12581259
contentTabIndex: number | null = null;
12591260
headerPosition: MatTabHeaderPosition = 'above';
12601261
ariaLabel: string;
12611262
ariaLabelledby: string;
1262-
handleFocus(event: any) {
1263+
handleFocus(event: MatTabChangeEvent) {
12631264
this.focusEvent = event;
12641265
}
1265-
handleSelection(event: any) {
1266+
handleSelection(event: MatTabChangeEvent) {
12661267
this.selectEvent = event;
12671268
}
12681269
animationDone() {}
@@ -1292,13 +1293,13 @@ class SimpleDynamicTabsTestApp {
12921293
{label: 'Label 3', content: 'Content 3'},
12931294
];
12941295
selectedIndex: number = 1;
1295-
focusEvent: any;
1296-
selectEvent: any;
1296+
focusEvent: MatTabChangeEvent;
1297+
selectEvent: MatTabChangeEvent;
12971298
disablePagination = false;
1298-
handleFocus(event: any) {
1299+
handleFocus(event: MatTabChangeEvent) {
12991300
this.focusEvent = event;
13001301
}
1301-
handleSelection(event: any) {
1302+
handleSelection(event: MatTabChangeEvent) {
13021303
this.selectEvent = event;
13031304
}
13041305
}
@@ -1372,11 +1373,11 @@ class AsyncTabsTestApp implements OnInit {
13721373
{label: 'two', content: 'two'},
13731374
];
13741375

1375-
tabs: Observable<any>;
1376+
tabs: Observable<typeof this._tabs>;
13761377

13771378
ngOnInit() {
13781379
// Use ngOnInit because there is some issue with scheduling the async task in the constructor.
1379-
this.tabs = new Observable((observer: any) => {
1380+
this.tabs = new Observable((observer: Subscriber<typeof this._tabs>) => {
13801381
setTimeout(() => observer.next(this._tabs));
13811382
});
13821383
}
@@ -1397,7 +1398,7 @@ class TabGroupWithSimpleApi {
13971398
preserveContent = false;
13981399
otherLabel = 'Fruit';
13991400
otherContent = 'Apples, grapes';
1400-
@ViewChild('legumes') legumes: any;
1401+
@ViewChild('legumes') legumes: HTMLParagraphElement;
14011402
}
14021403

14031404
@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',
@@ -75,11 +76,11 @@ export class MatTab implements OnInit, OnChanges, OnDestroy {
7576
* Template provided in the tab content that will be used if present, used to enable lazy-loading
7677
*/
7778
@ContentChild(MatTabContent, {read: TemplateRef, static: true})
78-
// We need an initializer here to avoid a TS error. The value will be set in `ngAfterViewInit`.
79-
private _explicitContent: TemplateRef<any> = undefined!;
79+
// The value will be set in `ngAfterViewInit`.
80+
private _explicitContent?: TemplateRef<unknown>;
8081

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

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

0 commit comments

Comments
 (0)