Skip to content

Commit 1f6504b

Browse files
committed
refactor(multiple): Remove any in sort, stepper, table, timepicker, tooltip, tree
1 parent 27309fd commit 1f6504b

File tree

13 files changed

+93
-72
lines changed

13 files changed

+93
-72
lines changed

goldens/material/stepper/index.api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
5050
}
5151

5252
// @public
53-
export class MatStepContent {
53+
export class MatStepContent<C = unknown> {
5454
constructor(...args: unknown[]);
5555
// (undocumented)
56-
_template: TemplateRef<any>;
56+
_template: TemplateRef<C>;
5757
// (undocumented)
58-
static ɵdir: i0.ɵɵDirectiveDeclaration<MatStepContent, "ng-template[matStepContent]", never, {}, {}, never, never, true, never>;
58+
static ɵdir: i0.ɵɵDirectiveDeclaration<MatStepContent<any>, "ng-template[matStepContent]", never, {}, {}, never, never, true, never>;
5959
// (undocumented)
60-
static ɵfac: i0.ɵɵFactoryDeclaration<MatStepContent, never>;
60+
static ɵfac: i0.ɵɵFactoryDeclaration<MatStepContent<any>, never>;
6161
}
6262

6363
// @public (undocumented)

goldens/material/timepicker/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ export class MatTimepickerInput<D> implements MatTimepickerConnectedInput<D>, Co
109109
// (undocumented)
110110
ngOnDestroy(): void;
111111
readonly openOnClick: InputSignalWithTransform<boolean, unknown>;
112-
registerOnChange(fn: (value: any) => void): void;
112+
registerOnChange(fn: (value: unknown) => void): void;
113113
registerOnTouched(fn: () => void): void;
114114
registerOnValidatorChange(fn: () => void): void;
115115
setDisabledState(isDisabled: boolean): void;
116116
readonly timepicker: InputSignal<MatTimepicker<D>>;
117117
timepickerValueAssigned(value: D | null): void;
118118
validate(control: AbstractControl): ValidationErrors | null;
119119
readonly value: ModelSignal<D | null>;
120-
writeValue(value: any): void;
120+
writeValue(value: unknown): void;
121121
// (undocumented)
122122
static ɵdir: i0.ɵɵDirectiveDeclaration<MatTimepickerInput<any>, "input[matTimepicker]", ["matTimepickerInput"], { "value": { "alias": "value"; "required": false; "isSignal": true; }; "timepicker": { "alias": "matTimepicker"; "required": true; "isSignal": true; }; "min": { "alias": "matTimepickerMin"; "required": false; "isSignal": true; }; "max": { "alias": "matTimepickerMax"; "required": false; "isSignal": true; }; "openOnClick": { "alias": "matTimepickerOpenOnClick"; "required": false; "isSignal": true; }; "disabledInput": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; }, never, never, true, never>;
123123
// (undocumented)

goldens/material/tooltip/index.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
7676
y: number;
7777
}): void;
7878
get tooltipClass(): string | string[] | Set<string> | {
79-
[key: string]: any;
79+
[key: string]: unknown;
8080
};
8181
set tooltipClass(value: string | string[] | Set<string> | {
82-
[key: string]: any;
82+
[key: string]: unknown;
8383
});
8484
// (undocumented)
8585
_tooltipInstance: TooltipComponent | null;
@@ -143,7 +143,7 @@ export class TooltipComponent implements OnDestroy {
143143
show(delay: number): void;
144144
_tooltip: ElementRef<HTMLElement>;
145145
tooltipClass: string | string[] | Set<string> | {
146-
[key: string]: any;
146+
[key: string]: unknown;
147147
};
148148
_triggerElement: HTMLElement;
149149
// (undocumented)

src/material/sort/sort.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ class SimpleMatSortApp {
504504
}
505505
}
506506

507-
class FakeDataSource extends DataSource<any> {
508-
connect(collectionViewer: CollectionViewer): Observable<any[]> {
507+
class FakeDataSource extends DataSource<never> {
508+
connect(collectionViewer: CollectionViewer): Observable<never[]> {
509509
return collectionViewer.viewChange.pipe(map(() => []));
510510
}
511511
disconnect() {}

src/material/stepper/step-content.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {Directive, TemplateRef, inject} from '@angular/core';
1414
@Directive({
1515
selector: 'ng-template[matStepContent]',
1616
})
17-
export class MatStepContent {
18-
_template = inject<TemplateRef<any>>(TemplateRef);
17+
export class MatStepContent<C = unknown> {
18+
_template = inject<TemplateRef<C>>(TemplateRef);
1919

2020
constructor(...args: unknown[]);
2121
constructor() {}

src/material/table/table-data-source.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,14 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
229229
* @returns Whether the filter matches against the data
230230
*/
231231
filterPredicate: (data: T, filter: string) => boolean = (data: T, filter: string): boolean => {
232+
if ((typeof ngDevMode === 'undefined' || ngDevMode) && typeof data !== 'object') {
233+
throw new Error('Default implementation of filterPredicate requires data to be object.');
234+
}
235+
232236
// Transform the filter by converting it to lowercase and removing whitespace.
233237
const transformedFilter = filter.trim().toLowerCase();
234238
// Loops over the values in the array and returns true if any of them match the filter string
235-
return Object.values(data as {[key: string]: any}).some(value =>
239+
return Object.values(data as object).some(value =>
236240
`${value}`.toLowerCase().includes(transformedFilter),
237241
);
238242
};

src/material/table/table.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ describe('MatTable', () => {
1616
const data = fixture.componentInstance.dataSource!.data;
1717
expectTableToMatchContent(tableElement, [
1818
['Column A', 'Column B', 'Column C'],
19-
[data[0].a, data[0].b, data[0].c],
20-
[data[1].a, data[1].b, data[1].c],
21-
[data[2].a, data[2].b, data[2].c],
19+
[data[0].a, data[0].b, data[0].c] as string[],
20+
[data[1].a, data[1].b, data[1].c] as string[],
21+
[data[2].a, data[2].b, data[2].c] as string[],
2222
['fourth_row'],
2323
['Footer A', 'Footer B', 'Footer C'],
2424
]);
@@ -64,10 +64,10 @@ describe('MatTable', () => {
6464
const data = fixture.componentInstance.dataSource!.data;
6565
expectTableToMatchContent(tableElement, [
6666
['Column A', 'Column B', 'Column C'],
67-
[data[0].a, data[0].b, data[0].c],
68-
[data[1].a, data[1].b, data[1].c],
69-
[data[2].a, data[2].b, data[2].c],
70-
[data[3].a, data[3].b, data[3].c],
67+
[data[0].a, data[0].b, data[0].c] as string[],
68+
[data[1].a, data[1].b, data[1].c] as string[],
69+
[data[2].a, data[2].b, data[2].c] as string[],
70+
[data[3].a, data[3].b, data[3].c] as string[],
7171
]);
7272
});
7373

@@ -159,9 +159,9 @@ describe('MatTable', () => {
159159
const data = fixture.componentInstance.dataSource!.data;
160160
expectTableToMatchContent(tableElement, [
161161
['Column A', 'Column B', 'Column C'],
162-
[data[0].a, data[0].b, data[0].c],
163-
[data[1].a, data[1].b, data[1].c],
164-
[data[2].a, data[2].b, data[2].c],
162+
[data[0].a, data[0].b, data[0].c] as string[],
163+
[data[1].a, data[1].b, data[1].c] as string[],
164+
[data[2].a, data[2].b, data[2].c] as string[],
165165
]);
166166
});
167167

@@ -173,9 +173,9 @@ describe('MatTable', () => {
173173
const data = fixture.componentInstance.dataSource!.data;
174174
expectTableToMatchContent(tableElement, [
175175
['Column A', 'Column B', 'Column C'],
176-
[data[0].a, data[0].b, data[0].c],
177-
[data[1].a, data[1].b, data[1].c],
178-
[data[2].a, data[2].b, data[2].c],
176+
[data[0].a, data[0].b, data[0].c] as string[],
177+
[data[1].a, data[1].b, data[1].c] as string[],
178+
[data[2].a, data[2].b, data[2].c] as string[],
179179
]);
180180
});
181181

@@ -357,7 +357,7 @@ describe('MatTable', () => {
357357
]);
358358

359359
// Change the filter to a falsy value that might come in from the view.
360-
dataSource.filter = 0 as any;
360+
dataSource.filter = 0 as unknown as string;
361361
flushMicrotasks();
362362
fixture.detectChanges();
363363
expectTableToMatchContent(tableElement, [
@@ -604,7 +604,7 @@ describe('MatTable', () => {
604604
['Footer A', 'Footer B', 'Footer C'],
605605
]);
606606

607-
dataSource.data = {} as any;
607+
dataSource.data = {} as TestData[];
608608
fixture.changeDetectorRef.markForCheck();
609609
fixture.detectChanges();
610610
expectTableToMatchContent(tableElement, [
@@ -1108,7 +1108,7 @@ function getActualTableContent(tableElement: Element): string[][] {
11081108
return actualTableContent.map(row => row.map(cell => cell.textContent!.trim()));
11091109
}
11101110

1111-
export function expectTableToMatchContent(tableElement: Element, expected: any[]) {
1111+
export function expectTableToMatchContent(tableElement: Element, expected: string[][]) {
11121112
const missedExpectations: string[] = [];
11131113
function checkCellContent(actualCell: string, expectedCell: string) {
11141114
if (actualCell !== expectedCell) {
@@ -1134,7 +1134,7 @@ export function expectTableToMatchContent(tableElement: Element, expected: any[]
11341134
}
11351135

11361136
row.forEach((actualCell, cellIndex) => {
1137-
const expectedCell = expectedRow ? expectedRow[cellIndex] : null;
1137+
const expectedCell = expectedRow[cellIndex];
11381138
checkCellContent(actualCell, expectedCell);
11391139
});
11401140
});

src/material/timepicker/timepicker-input.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MatTimepickerInput<D>
8888
private _dateFormats = inject(MAT_DATE_FORMATS, {optional: true})!;
8989
private _formField = inject(MAT_FORM_FIELD, {optional: true});
9090

91-
private _onChange: ((value: any) => void) | undefined;
91+
private _onChange: ((value: unknown) => void) | undefined;
9292
private _onTouched: (() => void) | undefined;
9393
private _validatorOnChange: (() => void) | undefined;
9494
private _cleanupClick: () => void;
@@ -195,7 +195,7 @@ export class MatTimepickerInput<D>
195195
* Implemented as a part of `ControlValueAccessor`.
196196
* @docs-private
197197
*/
198-
writeValue(value: any): void {
198+
writeValue(value: unknown): void {
199199
// Note that we need to deserialize here, rather than depend on the value change effect,
200200
// because `getValidDateOrNull` will clobber the value if it's parseable, but not created by
201201
// the current adapter (see #30140).
@@ -207,7 +207,7 @@ export class MatTimepickerInput<D>
207207
* Implemented as a part of `ControlValueAccessor`.
208208
* @docs-private
209209
*/
210-
registerOnChange(fn: (value: any) => void): void {
210+
registerOnChange(fn: (value: unknown) => void): void {
211211
this._onChange = fn;
212212
}
213213

src/material/tooltip/tooltip.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ describe('MatTooltip', () => {
13861386
fixture.detectChanges();
13871387

13881388
const styles = fixture.nativeElement.querySelector('button').style;
1389-
expect(styles.touchAction || (styles as any).webkitUserDrag).toBe('none');
1389+
expect(styles.touchAction || styles.webkitUserDrag).toBe('none');
13901390
});
13911391

13921392
it('should allow native touch interactions if touch gestures are turned off', () => {
@@ -1395,7 +1395,7 @@ describe('MatTooltip', () => {
13951395
fixture.detectChanges();
13961396

13971397
const styles = fixture.nativeElement.querySelector('button').style;
1398-
expect(styles.touchAction || (styles as any).webkitUserDrag).toBeFalsy();
1398+
expect(styles.touchAction || styles.webkitUserDrag).toBeFalsy();
13991399
});
14001400

14011401
it('should allow text selection on inputs when gestures are set to auto', () => {
@@ -1407,13 +1407,13 @@ describe('MatTooltip', () => {
14071407

14081408
expect(inputStyle.userSelect).toBeFalsy();
14091409
expect(inputStyle.webkitUserSelect).toBeFalsy();
1410-
expect((inputStyle as any).msUserSelect).toBeFalsy();
1411-
expect((inputStyle as any).MozUserSelect).toBeFalsy();
1410+
expect(inputStyle.msUserSelect).toBeFalsy();
1411+
expect(inputStyle.MozUserSelect).toBeFalsy();
14121412

14131413
expect(textareaStyle.userSelect).toBeFalsy();
14141414
expect(textareaStyle.webkitUserSelect).toBeFalsy();
1415-
expect((textareaStyle as any).msUserSelect).toBeFalsy();
1416-
expect((textareaStyle as any).MozUserSelect).toBeFalsy();
1415+
expect(textareaStyle.msUserSelect).toBeFalsy();
1416+
expect(textareaStyle.MozUserSelect).toBeFalsy();
14171417
});
14181418

14191419
it('should disable text selection on inputs when gestures are set to on', () => {
@@ -1425,14 +1425,14 @@ describe('MatTooltip', () => {
14251425
const inputUserSelect =
14261426
inputStyle.userSelect ||
14271427
inputStyle.webkitUserSelect ||
1428-
(inputStyle as any).msUserSelect ||
1429-
(inputStyle as any).MozUserSelect;
1428+
inputStyle.msUserSelect ||
1429+
inputStyle.MozUserSelect;
14301430
const textareaStyle = fixture.componentInstance.textarea.nativeElement.style;
14311431
const textareaUserSelect =
14321432
textareaStyle.userSelect ||
14331433
textareaStyle.webkitUserSelect ||
1434-
(textareaStyle as any).msUserSelect ||
1435-
(textareaStyle as any).MozUserSelect;
1434+
textareaStyle.msUserSelect ||
1435+
textareaStyle.MozUserSelect;
14361436

14371437
expect(inputUserSelect).toBe('none');
14381438
expect(textareaUserSelect).toBe('none');
@@ -1570,7 +1570,7 @@ describe('MatTooltip', () => {
15701570
})
15711571
class BasicTooltipDemo {
15721572
position: TooltipPosition = 'below';
1573-
message: any = initialTooltipMessage;
1573+
message: string | number = initialTooltipMessage;
15741574
showButton = true;
15751575
showTooltipClass = false;
15761576
tooltipDisabled = false;
@@ -1683,7 +1683,7 @@ class TooltipOnDraggableElement {
16831683
imports: [MatTooltip],
16841684
})
16851685
class TooltipDemoWithoutPositionBinding {
1686-
message: any = initialTooltipMessage;
1686+
message: string = initialTooltipMessage;
16871687
@ViewChild(MatTooltip) tooltip: MatTooltip;
16881688
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
16891689
}
@@ -1705,7 +1705,7 @@ class TooltipDemoWithoutTooltipClassBinding {
17051705
imports: [MatTooltip],
17061706
})
17071707
class TooltipDemoWithTooltipClassBinding {
1708-
message: any = initialTooltipMessage;
1708+
message: string = initialTooltipMessage;
17091709
@ViewChild(MatTooltip) tooltip: MatTooltip;
17101710
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
17111711
}

src/material/tooltip/tooltip.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ import {ComponentPortal} from '@angular/cdk/portal';
5555
import {Observable, Subject} from 'rxjs';
5656
import {_animationsDisabled} from '../core';
5757

58+
declare global {
59+
interface CSSStyleDeclaration {
60+
msUserSelect: string;
61+
MozUserSelect: string;
62+
webkitUserDrag: string;
63+
webkitTapHighlightColor: string;
64+
}
65+
}
66+
5867
/** Possible positions for a tooltip. */
5968
export type TooltipPosition = 'left' | 'right' | 'above' | 'below' | 'before' | 'after';
6069

@@ -194,7 +203,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
194203
private _position: TooltipPosition = 'below';
195204
private _positionAtOrigin: boolean = false;
196205
private _disabled: boolean = false;
197-
private _tooltipClass: string | string[] | Set<string> | {[key: string]: any};
206+
private _tooltipClass: string | string[] | Set<string> | {[key: string]: unknown};
198207
private _viewInitialized = false;
199208
private _pointerExitEventsInitialized = false;
200209
private readonly _tooltipComponent = TooltipComponent;
@@ -336,7 +345,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
336345
return this._tooltipClass;
337346
}
338347

339-
set tooltipClass(value: string | string[] | Set<string> | {[key: string]: any}) {
348+
set tooltipClass(value: string | string[] | Set<string> | {[key: string]: unknown}) {
340349
this._tooltipClass = value;
341350
if (this._tooltipInstance) {
342351
this._setTooltipClass(this._tooltipClass);
@@ -701,7 +710,9 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
701710
}
702711

703712
/** Updates the tooltip class */
704-
private _setTooltipClass(tooltipClass: string | string[] | Set<string> | {[key: string]: any}) {
713+
private _setTooltipClass(
714+
tooltipClass: string | string[] | Set<string> | {[key: string]: unknown},
715+
) {
705716
if (this._tooltipInstance) {
706717
this._tooltipInstance.tooltipClass = tooltipClass;
707718
this._tooltipInstance._markForCheck();
@@ -889,20 +900,20 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
889900
// textareas, because it prevents the user from typing into them on iOS Safari.
890901
if (gestures === 'on' || (element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA')) {
891902
style.userSelect =
892-
(style as any).msUserSelect =
903+
style.msUserSelect =
893904
style.webkitUserSelect =
894-
(style as any).MozUserSelect =
905+
style.MozUserSelect =
895906
'none';
896907
}
897908

898909
// If we have `auto` gestures and the element uses native HTML dragging,
899910
// we don't set `-webkit-user-drag` because it prevents the native behavior.
900911
if (gestures === 'on' || !element.draggable) {
901-
(style as any).webkitUserDrag = 'none';
912+
style.webkitUserDrag = 'none';
902913
}
903914

904915
style.touchAction = 'none';
905-
(style as any).webkitTapHighlightColor = 'transparent';
916+
style.webkitTapHighlightColor = 'transparent';
906917
}
907918
}
908919

@@ -963,7 +974,7 @@ export class TooltipComponent implements OnDestroy {
963974
message: string;
964975

965976
/** Classes to be added to the tooltip. Supports the same syntax as `ngClass`. */
966-
tooltipClass: string | string[] | Set<string> | {[key: string]: any};
977+
tooltipClass: string | string[] | Set<string> | {[key: string]: unknown};
967978

968979
/** The timeout ID of any current timer set to show the tooltip */
969980
private _showTimeoutId: ReturnType<typeof setTimeout> | undefined;

0 commit comments

Comments
 (0)