Skip to content

Commit 264a000

Browse files
committed
fix(material/tooltip): Remove almost all any
1 parent 6fbcf55 commit 264a000

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

src/material/tooltip/tooltip.spec.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import {FocusMonitor} from '@angular/cdk/a11y';
22
import {Direction, Directionality} from '@angular/cdk/bidi';
33
import {ESCAPE} from '@angular/cdk/keycodes';
4-
import {CdkScrollable, OverlayContainer, OverlayModule} from '@angular/cdk/overlay';
4+
import {
5+
CdkScrollable,
6+
ConnectedPosition,
7+
FlexibleConnectedPositionStrategy,
8+
OverlayContainer,
9+
OverlayModule,
10+
} from '@angular/cdk/overlay';
511
import {Platform} from '@angular/cdk/platform';
612
import {
713
createFakeEvent,
@@ -1423,7 +1429,7 @@ describe('MatTooltip', () => {
14231429
fixture.detectChanges();
14241430

14251431
const styles = fixture.nativeElement.querySelector('button').style;
1426-
expect(styles.touchAction || (styles as any).webkitUserDrag).toBe('none');
1432+
expect(styles.touchAction || styles.webkitUserDrag).toBe('none');
14271433
});
14281434

14291435
it('should allow native touch interactions if touch gestures are turned off', () => {
@@ -1432,7 +1438,7 @@ describe('MatTooltip', () => {
14321438
fixture.detectChanges();
14331439

14341440
const styles = fixture.nativeElement.querySelector('button').style;
1435-
expect(styles.touchAction || (styles as any).webkitUserDrag).toBeFalsy();
1441+
expect(styles.touchAction || styles.webkitUserDrag).toBeFalsy();
14361442
});
14371443

14381444
it('should allow text selection on inputs when gestures are set to auto', () => {
@@ -1444,13 +1450,13 @@ describe('MatTooltip', () => {
14441450

14451451
expect(inputStyle.userSelect).toBeFalsy();
14461452
expect(inputStyle.webkitUserSelect).toBeFalsy();
1447-
expect((inputStyle as any).msUserSelect).toBeFalsy();
1448-
expect((inputStyle as any).MozUserSelect).toBeFalsy();
1453+
expect(inputStyle.msUserSelect).toBeFalsy();
1454+
expect(inputStyle.MozUserSelect).toBeFalsy();
14491455

14501456
expect(textareaStyle.userSelect).toBeFalsy();
14511457
expect(textareaStyle.webkitUserSelect).toBeFalsy();
1452-
expect((textareaStyle as any).msUserSelect).toBeFalsy();
1453-
expect((textareaStyle as any).MozUserSelect).toBeFalsy();
1458+
expect(textareaStyle.msUserSelect).toBeFalsy();
1459+
expect(textareaStyle.MozUserSelect).toBeFalsy();
14541460
});
14551461

14561462
it('should disable text selection on inputs when gestures are set to on', () => {
@@ -1462,14 +1468,14 @@ describe('MatTooltip', () => {
14621468
const inputUserSelect =
14631469
inputStyle.userSelect ||
14641470
inputStyle.webkitUserSelect ||
1465-
(inputStyle as any).msUserSelect ||
1466-
(inputStyle as any).MozUserSelect;
1471+
inputStyle.msUserSelect ||
1472+
inputStyle.MozUserSelect;
14671473
const textareaStyle = fixture.componentInstance.textarea.nativeElement.style;
14681474
const textareaUserSelect =
14691475
textareaStyle.userSelect ||
14701476
textareaStyle.webkitUserSelect ||
1471-
(textareaStyle as any).msUserSelect ||
1472-
(textareaStyle as any).MozUserSelect;
1477+
textareaStyle.msUserSelect ||
1478+
textareaStyle.MozUserSelect;
14731479

14741480
expect(inputUserSelect).toBe('none');
14751481
expect(textareaUserSelect).toBe('none');
@@ -1608,7 +1614,7 @@ describe('MatTooltip', () => {
16081614
})
16091615
class BasicTooltipDemo {
16101616
position = 'below';
1611-
message: any = initialTooltipMessage;
1617+
message: string | number = initialTooltipMessage;
16121618
showButton = true;
16131619
showTooltipClass = false;
16141620
tooltipDisabled = false;
@@ -1725,7 +1731,7 @@ class TooltipOnDraggableElement {
17251731
standalone: false,
17261732
})
17271733
class TooltipDemoWithoutPositionBinding {
1728-
message: any = initialTooltipMessage;
1734+
message: string = initialTooltipMessage;
17291735
@ViewChild(MatTooltip) tooltip: MatTooltip;
17301736
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
17311737
}
@@ -1749,7 +1755,7 @@ class TooltipDemoWithoutTooltipClassBinding {
17491755
standalone: false,
17501756
})
17511757
class TooltipDemoWithTooltipClassBinding {
1752-
message: any = initialTooltipMessage;
1758+
message: string = initialTooltipMessage;
17531759
@ViewChild(MatTooltip) tooltip: MatTooltip;
17541760
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
17551761
}

src/material/tooltip/tooltip.ts

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

55+
declare global {
56+
interface CSSStyleDeclaration {
57+
msUserSelect: string;
58+
MozUserSelect: string;
59+
webkitUserDrag: string;
60+
webkitTapHighlightColor: string;
61+
}
62+
}
63+
5564
/** Possible positions for a tooltip. */
5665
export type TooltipPosition = 'left' | 'right' | 'above' | 'below' | 'before' | 'after';
5766

@@ -219,7 +228,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
219228
private _position: TooltipPosition = 'below';
220229
private _positionAtOrigin: boolean = false;
221230
private _disabled: boolean = false;
222-
private _tooltipClass: string | string[] | Set<string> | {[key: string]: any};
231+
private _tooltipClass: string | string[] | Set<string> | {[key: string]: unknown};
223232
private _viewInitialized = false;
224233
private _pointerExitEventsInitialized = false;
225234
private readonly _tooltipComponent = TooltipComponent;
@@ -361,7 +370,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
361370
return this._tooltipClass;
362371
}
363372

364-
set tooltipClass(value: string | string[] | Set<string> | {[key: string]: any}) {
373+
set tooltipClass(value: string | string[] | Set<string> | {[key: string]: unknown}) {
365374
this._tooltipClass = value;
366375
if (this._tooltipInstance) {
367376
this._setTooltipClass(this._tooltipClass);
@@ -723,7 +732,9 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
723732
}
724733

725734
/** Updates the tooltip class */
726-
private _setTooltipClass(tooltipClass: string | string[] | Set<string> | {[key: string]: any}) {
735+
private _setTooltipClass(
736+
tooltipClass: string | string[] | Set<string> | {[key: string]: unknown},
737+
) {
727738
if (this._tooltipInstance) {
728739
this._tooltipInstance.tooltipClass = tooltipClass;
729740
this._tooltipInstance._markForCheck();
@@ -911,20 +922,20 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
911922
// textareas, because it prevents the user from typing into them on iOS Safari.
912923
if (gestures === 'on' || (element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA')) {
913924
style.userSelect =
914-
(style as any).msUserSelect =
925+
style.msUserSelect =
915926
style.webkitUserSelect =
916-
(style as any).MozUserSelect =
927+
style.MozUserSelect =
917928
'none';
918929
}
919930

920931
// If we have `auto` gestures and the element uses native HTML dragging,
921932
// we don't set `-webkit-user-drag` because it prevents the native behavior.
922933
if (gestures === 'on' || !element.draggable) {
923-
(style as any).webkitUserDrag = 'none';
934+
style.webkitUserDrag = 'none';
924935
}
925936

926937
style.touchAction = 'none';
927-
(style as any).webkitTapHighlightColor = 'transparent';
938+
style.webkitTapHighlightColor = 'transparent';
928939
}
929940
}
930941

@@ -985,7 +996,7 @@ export class TooltipComponent implements OnDestroy {
985996
message: string;
986997

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

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

0 commit comments

Comments
 (0)