Skip to content

Commit 046b854

Browse files
committed
refactor(multiple): Remove any type
1 parent 27309fd commit 046b854

File tree

20 files changed

+194
-137
lines changed

20 files changed

+194
-137
lines changed

goldens/material/snack-bar/index.api.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import { TemplateRef } from '@angular/core';
3232
import { ViewContainerRef } from '@angular/core';
3333

3434
// @public
35-
export const MAT_SNACK_BAR_DATA: InjectionToken<any>;
35+
export const MAT_SNACK_BAR_DATA: InjectionToken<unknown>;
3636

3737
// @public
38-
export const MAT_SNACK_BAR_DEFAULT_OPTIONS: InjectionToken<MatSnackBarConfig<any>>;
38+
export const MAT_SNACK_BAR_DEFAULT_OPTIONS: InjectionToken<MatSnackBarConfig<unknown>>;
3939

4040
// @public
4141
export class MatSnackBar implements OnDestroy {
@@ -45,10 +45,10 @@ export class MatSnackBar implements OnDestroy {
4545
// (undocumented)
4646
ngOnDestroy(): void;
4747
open(message: string, action?: string, config?: MatSnackBarConfig): MatSnackBarRef<TextOnlySnackBar>;
48-
get _openedSnackBarRef(): MatSnackBarRef<any> | null;
49-
set _openedSnackBarRef(value: MatSnackBarRef<any> | null);
50-
openFromComponent<T, D = any>(component: ComponentType<T>, config?: MatSnackBarConfig<D>): MatSnackBarRef<T>;
51-
openFromTemplate(template: TemplateRef<any>, config?: MatSnackBarConfig): MatSnackBarRef<EmbeddedViewRef<any>>;
48+
get _openedSnackBarRef(): MatSnackBarRef<unknown> | null;
49+
set _openedSnackBarRef(value: MatSnackBarRef<unknown> | null);
50+
openFromComponent<T, D = unknown>(component: ComponentType<T>, config?: MatSnackBarConfig<D>): MatSnackBarRef<T>;
51+
openFromTemplate<C = unknown>(template: TemplateRef<C>, config?: MatSnackBarConfig): MatSnackBarRef<EmbeddedViewRef<C>>;
5252
simpleSnackBarComponent: typeof SimpleSnackBar;
5353
snackBarContainerComponent: typeof MatSnackBarContainer;
5454
// (undocumented)
@@ -74,7 +74,7 @@ export class MatSnackBarActions {
7474
}
7575

7676
// @public
77-
export class MatSnackBarConfig<D = any> {
77+
export class MatSnackBarConfig<D = unknown> {
7878
announcementMessage?: string;
7979
data?: D | null;
8080
direction?: Direction;
@@ -168,7 +168,7 @@ export class SimpleSnackBar implements TextOnlySnackBar {
168168
constructor(...args: unknown[]);
169169
action(): void;
170170
// (undocumented)
171-
data: any;
171+
data: TextOnlySnackBarData;
172172
get hasAction(): boolean;
173173
// (undocumented)
174174
snackBarRef: MatSnackBarRef<SimpleSnackBar>;
@@ -183,16 +183,21 @@ export interface TextOnlySnackBar {
183183
// (undocumented)
184184
action: () => void;
185185
// (undocumented)
186-
data: {
187-
message: string;
188-
action: string;
189-
};
186+
data: TextOnlySnackBarData;
190187
// (undocumented)
191188
hasAction: boolean;
192189
// (undocumented)
193190
snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
194191
}
195192

193+
// @public
194+
export interface TextOnlySnackBarData {
195+
// (undocumented)
196+
action: string;
197+
// (undocumented)
198+
message: string;
199+
}
200+
196201
// (No @packageDocumentation comment for this package)
197202

198203
```

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/snack-bar/simple-snack-bar.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import {MatSnackBarRef} from './snack-bar-ref';
1212
import {MAT_SNACK_BAR_DATA} from './snack-bar-config';
1313
import {MatSnackBarAction, MatSnackBarActions, MatSnackBarLabel} from './snack-bar-content';
1414

15+
/** Input data for a simple snack bar component that has a message and a single action. */
16+
export interface TextOnlySnackBarData {
17+
message: string;
18+
action: string;
19+
}
20+
1521
/**
1622
* Interface for a simple snack bar component that has a message and a single action.
1723
*/
1824
export interface TextOnlySnackBar {
19-
data: {message: string; action: string};
20-
snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
25+
data: TextOnlySnackBarData;
26+
snackBarRef: MatSnackBarRef<TextOnlySnackBar, TextOnlySnackBarData>;
2127
action: () => void;
2228
hasAction: boolean;
2329
}
@@ -35,8 +41,8 @@ export interface TextOnlySnackBar {
3541
},
3642
})
3743
export class SimpleSnackBar implements TextOnlySnackBar {
38-
snackBarRef = inject<MatSnackBarRef<SimpleSnackBar>>(MatSnackBarRef);
39-
data = inject(MAT_SNACK_BAR_DATA);
44+
snackBarRef = inject<MatSnackBarRef<SimpleSnackBar, TextOnlySnackBarData>>(MatSnackBarRef);
45+
data = inject<TextOnlySnackBarData>(MAT_SNACK_BAR_DATA);
4046

4147
constructor(...args: unknown[]);
4248
constructor() {}

src/material/snack-bar/snack-bar-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {AriaLivePoliteness} from '@angular/cdk/a11y';
1111
import {Direction} from '@angular/cdk/bidi';
1212

1313
/** Injection token that can be used to access the data that was passed in to a snack bar. */
14-
export const MAT_SNACK_BAR_DATA = new InjectionToken<any>('MatSnackBarData');
14+
export const MAT_SNACK_BAR_DATA = new InjectionToken<unknown>('MatSnackBarData');
1515

1616
/** Possible values for horizontalPosition on MatSnackBarConfig. */
1717
export type MatSnackBarHorizontalPosition = 'start' | 'center' | 'end' | 'left' | 'right';
@@ -22,7 +22,7 @@ export type MatSnackBarVerticalPosition = 'top' | 'bottom';
2222
/**
2323
* Configuration used when opening a snack-bar.
2424
*/
25-
export class MatSnackBarConfig<D = any> {
25+
export class MatSnackBarConfig<D = unknown> {
2626
/** The politeness level for the MatAriaLiveAnnouncer announcement. */
2727
politeness?: AriaLivePoliteness = 'polite';
2828

src/material/snack-bar/snack-bar-container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ const EXIT_ANIMATION = '_mat-snack-bar-exit';
6363
'(animationcancel)': 'onAnimationEnd($event.animationName)',
6464
},
6565
})
66-
export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy {
66+
export class MatSnackBarContainer<D = unknown> extends BasePortalOutlet implements OnDestroy {
6767
private _ngZone = inject(NgZone);
6868
readonly _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
6969
private _changeDetectorRef = inject(ChangeDetectorRef);
7070
private _platform = inject(Platform);
7171
protected _animationsDisabled = _animationsDisabled();
72-
snackBarConfig = inject(MatSnackBarConfig);
72+
snackBarConfig = inject<MatSnackBarConfig<D>>(MatSnackBarConfig);
7373

7474
private _document = inject(DOCUMENT);
7575
private _trackedModals = new Set<Element>();

src/material/snack-bar/snack-bar-ref.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ const MAX_TIMEOUT = Math.pow(2, 31) - 1;
2222
/**
2323
* Reference to a snack bar dispatched from the snack bar service.
2424
*/
25-
export class MatSnackBarRef<T> {
25+
export class MatSnackBarRef<T, D = unknown> {
2626
/** The instance of the component making up the content of the snack bar. */
2727
instance: T;
2828

2929
/**
3030
* The instance of the component making up the content of the snack bar.
3131
* @docs-private
3232
*/
33-
containerInstance: MatSnackBarContainer;
33+
containerInstance: MatSnackBarContainer<D>;
3434

3535
/** Subject for notifying the user that the snack bar has been dismissed. */
3636
private readonly _afterDismissed = new Subject<MatSnackBarDismiss>();
@@ -51,7 +51,7 @@ export class MatSnackBarRef<T> {
5151
private _dismissedByAction = false;
5252

5353
constructor(
54-
containerInstance: MatSnackBarContainer,
54+
containerInstance: MatSnackBarContainer<D>,
5555
private _overlayRef: OverlayRef,
5656
) {
5757
this.containerInstance = containerInstance;

src/material/snack-bar/snack-bar.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,11 @@ describe('MatSnackBar', () => {
585585
});
586586

587587
it('should be able to inject arbitrary user data', () => {
588+
const data: BurritosNotificationData = {
589+
burritoType: 'Chimichanga',
590+
};
588591
const snackBarRef = snackBar.openFromComponent(BurritosNotification, {
589-
data: {
590-
burritoType: 'Chimichanga',
591-
},
592+
data,
592593
});
593594

594595
expect(snackBarRef.instance.data)
@@ -997,17 +998,21 @@ class ComponentWithChildViewContainer {
997998
`,
998999
})
9991000
class ComponentWithTemplateRef {
1000-
@ViewChild(TemplateRef) templateRef: TemplateRef<any>;
1001+
@ViewChild(TemplateRef) templateRef: TemplateRef<unknown>;
10011002
localValue: string;
10021003
}
10031004

1005+
interface BurritosNotificationData {
1006+
burritoType: string;
1007+
}
1008+
10041009
/** Simple component for testing ComponentPortal. */
10051010
@Component({
10061011
template: '<p>Burritos are on the way.</p>',
10071012
})
10081013
class BurritosNotification {
10091014
snackBarRef = inject<MatSnackBarRef<BurritosNotification>>(MatSnackBarRef);
1010-
data = inject(MAT_SNACK_BAR_DATA);
1015+
data = inject<BurritosNotificationData>(MAT_SNACK_BAR_DATA);
10111016
}
10121017

10131018
@Component({

0 commit comments

Comments
 (0)