Skip to content

refactor(multiple): eliminate usages of any type (batch 1) #30741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions goldens/material/snack-bar/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import { TemplateRef } from '@angular/core';
import { ViewContainerRef } from '@angular/core';

// @public
export const MAT_SNACK_BAR_DATA: InjectionToken<any>;
export const MAT_SNACK_BAR_DATA: InjectionToken<unknown>;

// @public
export const MAT_SNACK_BAR_DEFAULT_OPTIONS: InjectionToken<MatSnackBarConfig<any>>;
export const MAT_SNACK_BAR_DEFAULT_OPTIONS: InjectionToken<MatSnackBarConfig<unknown>>;

// @public @deprecated
export function MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY(): MatSnackBarConfig;
Expand All @@ -48,10 +48,10 @@ export class MatSnackBar implements OnDestroy {
// (undocumented)
ngOnDestroy(): void;
open(message: string, action?: string, config?: MatSnackBarConfig): MatSnackBarRef<TextOnlySnackBar>;
get _openedSnackBarRef(): MatSnackBarRef<any> | null;
set _openedSnackBarRef(value: MatSnackBarRef<any> | null);
openFromComponent<T, D = any>(component: ComponentType<T>, config?: MatSnackBarConfig<D>): MatSnackBarRef<T>;
openFromTemplate(template: TemplateRef<any>, config?: MatSnackBarConfig): MatSnackBarRef<EmbeddedViewRef<any>>;
get _openedSnackBarRef(): MatSnackBarRef<unknown> | null;
set _openedSnackBarRef(value: MatSnackBarRef<unknown> | null);
openFromComponent<T, D = unknown>(component: ComponentType<T>, config?: MatSnackBarConfig<D>): MatSnackBarRef<T>;
openFromTemplate(template: TemplateRef<unknown>, config?: MatSnackBarConfig): MatSnackBarRef<EmbeddedViewRef<unknown>>;
simpleSnackBarComponent: typeof SimpleSnackBar;
snackBarContainerComponent: typeof MatSnackBarContainer;
// (undocumented)
Expand Down Expand Up @@ -82,7 +82,7 @@ export const matSnackBarAnimations: {
};

// @public
export class MatSnackBarConfig<D = any> {
export class MatSnackBarConfig<D = unknown> {
announcementMessage?: string;
data?: D | null;
direction?: Direction;
Expand Down Expand Up @@ -174,7 +174,7 @@ export class SimpleSnackBar implements TextOnlySnackBar {
constructor(...args: unknown[]);
action(): void;
// (undocumented)
data: any;
data: TextOnlySnackBarData;
get hasAction(): boolean;
// (undocumented)
snackBarRef: MatSnackBarRef<SimpleSnackBar>;
Expand All @@ -189,16 +189,21 @@ export interface TextOnlySnackBar {
// (undocumented)
action: () => void;
// (undocumented)
data: {
message: string;
action: string;
};
data: TextOnlySnackBarData;
// (undocumented)
hasAction: boolean;
// (undocumented)
snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
}

// @public
export interface TextOnlySnackBarData {
// (undocumented)
action: string;
// (undocumented)
message: string;
}

// (No @packageDocumentation comment for this package)

```
2 changes: 1 addition & 1 deletion goldens/material/stepper/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
export class MatStepContent {
constructor(...args: unknown[]);
// (undocumented)
_template: TemplateRef<any>;
_template: TemplateRef<unknown>;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatStepContent, "ng-template[matStepContent]", never, {}, {}, never, never, true, never>;
// (undocumented)
Expand Down
22 changes: 15 additions & 7 deletions goldens/material/tabs/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export const _MAT_INK_BAR_POSITIONER: InjectionToken<_MatInkBarPositioner>;
export function _MAT_INK_BAR_POSITIONER_FACTORY(): _MatInkBarPositioner;

// @public
export const MAT_TAB: InjectionToken<any>;
export const MAT_TAB: InjectionToken<MatTabBase>;

// @public
export const MAT_TAB_CONTENT: InjectionToken<MatTabContent>;

// @public
export const MAT_TAB_GROUP: InjectionToken<any>;
export const MAT_TAB_GROUP: InjectionToken<MatTabGroupBase>;

// @public
export const MAT_TAB_LABEL: InjectionToken<MatTabLabel>;
Expand Down Expand Up @@ -143,17 +143,17 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
}

// @public (undocumented)
export class MatTab implements OnInit, OnChanges, OnDestroy {
export class MatTab implements MatTabBase, OnInit, OnChanges, OnDestroy {
constructor(...args: unknown[]);
ariaLabel: string;
ariaLabelledby: string;
bodyClass: string | string[];
// (undocumented)
_closestTabGroup: any;
_closestTabGroup: MatTabGroupBase | null;
get content(): TemplatePortal | null;
disabled: boolean;
id: string | null;
_implicitContent: TemplateRef<any>;
_implicitContent?: TemplateRef<unknown>;
isActive: boolean;
labelClass: string | string[];
// (undocumented)
Expand All @@ -176,6 +176,10 @@ export class MatTab implements OnInit, OnChanges, OnDestroy {
static ɵfac: i0.ɵɵFactoryDeclaration<MatTab, never>;
}

// @public
export interface MatTabBase {
}

// @public
export class MatTabBody implements OnInit, OnDestroy {
constructor(...args: unknown[]);
Expand Down Expand Up @@ -231,7 +235,7 @@ export class MatTabChangeEvent {
export class MatTabContent {
constructor(...args: unknown[]);
// (undocumented)
template: TemplateRef<any>;
template: TemplateRef<unknown>;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatTabContent, "[matTabContent]", never, {}, {}, never, never, true, never>;
// (undocumented)
Expand Down Expand Up @@ -321,6 +325,10 @@ export class MatTabGroup implements AfterViewInit, AfterContentInit, AfterConten
static ɵfac: i0.ɵɵFactoryDeclaration<MatTabGroup, never>;
}

// @public
export interface MatTabGroupBase {
}

// @public
export interface MatTabGroupBaseHeader {
// (undocumented)
Expand Down Expand Up @@ -368,7 +376,7 @@ export type MatTabHeaderPosition = 'above' | 'below';
// @public
export class MatTabLabel extends CdkPortal {
// (undocumented)
_closestTab: any;
_closestTab: MatTabBase | null;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatTabLabel, "[mat-tab-label], [matTabLabel]", never, {}, {}, never, never, true, never>;
// (undocumented)
Expand Down
4 changes: 2 additions & 2 deletions goldens/material/timepicker/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ export class MatTimepickerInput<D> implements ControlValueAccessor, Validator, O
readonly min: InputSignalWithTransform<D | null, unknown>;
// (undocumented)
ngOnDestroy(): void;
registerOnChange(fn: (value: any) => void): void;
registerOnChange(fn: (value: unknown) => void): void;
registerOnTouched(fn: () => void): void;
registerOnValidatorChange(fn: () => void): void;
setDisabledState(isDisabled: boolean): void;
readonly timepicker: InputSignal<MatTimepicker<D>>;
validate(control: AbstractControl): ValidationErrors | null;
readonly value: ModelSignal<D | null>;
writeValue(value: any): void;
writeValue(value: unknown): void;
// (undocumented)
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; }; "disabledInput": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; }, never, never, true, never>;
// (undocumented)
Expand Down
6 changes: 3 additions & 3 deletions goldens/material/tooltip/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
y: number;
}): void;
get tooltipClass(): string | string[] | Set<string> | {
[key: string]: any;
[key: string]: unknown;
};
set tooltipClass(value: string | string[] | Set<string> | {
[key: string]: any;
[key: string]: unknown;
});
// (undocumented)
_tooltipInstance: TooltipComponent | null;
Expand Down Expand Up @@ -160,7 +160,7 @@ export class TooltipComponent implements OnDestroy {
show(delay: number): void;
_tooltip: ElementRef<HTMLElement>;
tooltipClass: string | string[] | Set<string> | {
[key: string]: any;
[key: string]: unknown;
};
_triggerElement: HTMLElement;
// (undocumented)
Expand Down
10 changes: 8 additions & 2 deletions src/material/snack-bar/simple-snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ import {MatSnackBarRef} from './snack-bar-ref';
import {MAT_SNACK_BAR_DATA} from './snack-bar-config';
import {MatSnackBarAction, MatSnackBarActions, MatSnackBarLabel} from './snack-bar-content';

/** Input data for the snack bar. */
export interface TextOnlySnackBarData {
message: string;
action: string;
}

/**
* Interface for a simple snack bar component that has a message and a single action.
*/
export interface TextOnlySnackBar {
data: {message: string; action: string};
data: TextOnlySnackBarData;
snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
action: () => void;
hasAction: boolean;
Expand All @@ -36,7 +42,7 @@ export interface TextOnlySnackBar {
})
export class SimpleSnackBar implements TextOnlySnackBar {
snackBarRef = inject<MatSnackBarRef<SimpleSnackBar>>(MatSnackBarRef);
data = inject(MAT_SNACK_BAR_DATA);
data = inject<TextOnlySnackBarData>(MAT_SNACK_BAR_DATA);

constructor(...args: unknown[]);
constructor() {}
Expand Down
4 changes: 2 additions & 2 deletions src/material/snack-bar/snack-bar-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {AriaLivePoliteness} from '@angular/cdk/a11y';
import {Direction} from '@angular/cdk/bidi';

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

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

Expand Down
15 changes: 10 additions & 5 deletions src/material/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,11 @@ describe('MatSnackBar', () => {
});

it('should be able to inject arbitrary user data', () => {
const data: BurritosNotificationData = {
burritoType: 'Chimichanga',
};
const snackBarRef = snackBar.openFromComponent(BurritosNotification, {
data: {
burritoType: 'Chimichanga',
},
data,
});

expect(snackBarRef.instance.data)
Expand Down Expand Up @@ -1013,17 +1014,21 @@ class ComponentWithChildViewContainer {
`,
})
class ComponentWithTemplateRef {
@ViewChild(TemplateRef) templateRef: TemplateRef<any>;
@ViewChild(TemplateRef) templateRef: TemplateRef<unknown>;
localValue: string;
}

interface BurritosNotificationData {
burritoType: string;
}

/** Simple component for testing ComponentPortal. */
@Component({
template: '<p>Burritos are on the way.</p>',
})
class BurritosNotification {
snackBarRef = inject<MatSnackBarRef<BurritosNotification>>(MatSnackBarRef);
data = inject(MAT_SNACK_BAR_DATA);
data = inject<BurritosNotificationData>(MAT_SNACK_BAR_DATA);
}

@Component({
Expand Down
27 changes: 16 additions & 11 deletions src/material/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MatSnackBar implements OnDestroy {
* If there is a parent snack-bar service, all operations should delegate to that parent
* via `_openedSnackBarRef`.
*/
private _snackBarRefAtThisLevel: MatSnackBarRef<any> | null = null;
private _snackBarRefAtThisLevel: MatSnackBarRef<unknown> | null = null;

/** The component that should be rendered as the snack bar's simple component. */
simpleSnackBarComponent = SimpleSnackBar;
Expand All @@ -75,12 +75,12 @@ export class MatSnackBar implements OnDestroy {
handsetCssClass = 'mat-mdc-snack-bar-handset';

/** Reference to the currently opened snackbar at *any* level. */
get _openedSnackBarRef(): MatSnackBarRef<any> | null {
get _openedSnackBarRef(): MatSnackBarRef<unknown> | null {
const parent = this._parentSnackBar;
return parent ? parent._openedSnackBarRef : this._snackBarRefAtThisLevel;
}

set _openedSnackBarRef(value: MatSnackBarRef<any> | null) {
set _openedSnackBarRef(value: MatSnackBarRef<unknown> | null) {
if (this._parentSnackBar) {
this._parentSnackBar._openedSnackBarRef = value;
} else {
Expand All @@ -98,11 +98,11 @@ export class MatSnackBar implements OnDestroy {
* @param component Component to be instantiated.
* @param config Extra configuration for the snack bar.
*/
openFromComponent<T, D = any>(
openFromComponent<T, D = unknown>(
component: ComponentType<T>,
config?: MatSnackBarConfig<D>,
): MatSnackBarRef<T> {
return this._attach(component, config) as MatSnackBarRef<T>;
return this._attach(component, config);
}

/**
Expand All @@ -113,9 +113,9 @@ export class MatSnackBar implements OnDestroy {
* @param config Extra configuration for the snack bar.
*/
openFromTemplate(
template: TemplateRef<any>,
template: TemplateRef<unknown>,
config?: MatSnackBarConfig,
): MatSnackBarRef<EmbeddedViewRef<any>> {
): MatSnackBarRef<EmbeddedViewRef<unknown>> {
return this._attach(template, config);
}

Expand Down Expand Up @@ -187,14 +187,19 @@ export class MatSnackBar implements OnDestroy {
/**
* Places a new component or a template as the content of the snack bar container.
*/
private _attach<T>(content: ComponentType<T>, userConfig?: MatSnackBarConfig): MatSnackBarRef<T>;
private _attach<T>(
content: TemplateRef<T>,
userConfig?: MatSnackBarConfig,
): MatSnackBarRef<EmbeddedViewRef<T>>;
private _attach<T>(
content: ComponentType<T> | TemplateRef<T>,
userConfig?: MatSnackBarConfig,
): MatSnackBarRef<T | EmbeddedViewRef<any>> {
): MatSnackBarRef<T | EmbeddedViewRef<unknown>> {
const config = {...new MatSnackBarConfig(), ...this._defaultConfig, ...userConfig};
const overlayRef = this._createOverlay(config);
const container = this._attachSnackBarContainer(overlayRef, config);
const snackBarRef = new MatSnackBarRef<T | EmbeddedViewRef<any>>(container, overlayRef);
const snackBarRef = new MatSnackBarRef<T | EmbeddedViewRef<unknown>>(container, overlayRef);

if (content instanceof TemplateRef) {
const portal = new TemplatePortal(content, null!, {
Expand Down Expand Up @@ -231,11 +236,11 @@ export class MatSnackBar implements OnDestroy {

this._animateSnackBar(snackBarRef, config);
this._openedSnackBarRef = snackBarRef;
return this._openedSnackBarRef;
return snackBarRef;
}

/** Animates the old snack bar out and the new one in. */
private _animateSnackBar(snackBarRef: MatSnackBarRef<any>, config: MatSnackBarConfig) {
private _animateSnackBar(snackBarRef: MatSnackBarRef<unknown>, config: MatSnackBarConfig) {
// When the snackbar is dismissed, clear the reference to it.
snackBarRef.afterDismissed().subscribe(() => {
// Clear the snackbar ref if it hasn't already been replaced by a newer snackbar.
Expand Down
4 changes: 2 additions & 2 deletions src/material/sort/sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ class SimpleMatSortApp {
}
}

class FakeDataSource extends DataSource<any> {
connect(collectionViewer: CollectionViewer): Observable<any[]> {
class FakeDataSource extends DataSource<never> {
connect(collectionViewer: CollectionViewer): Observable<never[]> {
return collectionViewer.viewChange.pipe(map(() => []));
}
disconnect() {}
Expand Down
2 changes: 1 addition & 1 deletion src/material/stepper/step-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Directive, TemplateRef, inject} from '@angular/core';
selector: 'ng-template[matStepContent]',
})
export class MatStepContent {
_template = inject<TemplateRef<any>>(TemplateRef);
_template = inject<TemplateRef<unknown>>(TemplateRef);

constructor(...args: unknown[]);
constructor() {}
Expand Down
Loading
Loading