Skip to content
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

refactor(multiple): eliminate usages of any type (batch 2) #30613

Draft
wants to merge 14 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Input hashes for repository rule npm_translate_lock(name = "npm2", pnpm_lock = "@//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=-1406867100
package.json=130765121
package.json=-306254715
patches/@angular__compiler-cli.patch=-65319555
pnpm-lock.yaml=-266832367
pnpm-lock.yaml=1755183230
pnpm-workspace.yaml=14857322
src/cdk/package.json=-908433069
yarn.lock=230420156
yarn.lock=-1568260908
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/youtube": "^0.1.0",
"rxjs": "^6.6.7",
"rxjs-tslint-rules": "^4.34.8",
"safevalues": "^1.2.0",
"tslib": "^2.3.1",
"zone.js": "~0.15.0"
},
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/google-maps/map-event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import {switchMap} from 'rxjs/operators';

type MapEventManagerTarget =
| {
addListener: (
addListener<T>(
name: string,
callback: (...args: any[]) => void,
) => google.maps.MapsEventListener | undefined;
callback: (args: T) => void,
): google.maps.MapsEventListener | undefined;
}
| undefined;

/** Manages event on a Google Maps object, ensuring that events are added only when necessary. */
export class MapEventManager {
/** Pending listeners that were added before the target was set. */
private _pending: {observable: Observable<any>; observer: Subscriber<any>}[] = [];
private _pending: {observable: Observable<unknown>; observer: Subscriber<unknown>}[] = [];
private _listeners: google.maps.MapsEventListener[] = [];
private _targetStream = new BehaviorSubject<MapEventManagerTarget>(undefined);

Expand Down
8 changes: 4 additions & 4 deletions src/material-date-fns-adapter/adapter/date-fns-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return new Date();
}

parse(value: any, parseFormat: string | string[]): Date | null {
parse(value: unknown, parseFormat: string | string[]): Date | null {
if (typeof value == 'string' && value.length > 0) {
const iso8601Date = parseISO(value);

Expand Down Expand Up @@ -222,7 +222,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
* (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an
* invalid date for all other values.
*/
override deserialize(value: any): Date | null {
override deserialize(value: unknown): Date | null {
if (typeof value === 'string') {
if (!value) {
return null;
Expand All @@ -235,7 +235,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return super.deserialize(value);
}

isDateInstance(obj: any): boolean {
isDateInstance(obj: unknown): obj is Date {
return isDate(obj);
}

Expand Down Expand Up @@ -277,7 +277,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return getSeconds(date);
}

override parseTime(value: any, parseFormat: string | string[]): Date | null {
override parseTime(value: unknown, parseFormat: string | string[]): Date | null {
return this.parse(value, parseFormat);
}

Expand Down
82 changes: 41 additions & 41 deletions src/material-experimental/column-resize/column-resize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class ElementDataSource extends DataSource<PeriodicElement> {
}

// There's 1px of variance between different browsers in terms of positioning.
const approximateMatcher = {
const approximateMatcher: jasmine.CustomMatcherFactories = {
isApproximately: () => ({
compare: (actual: number, expected: number) => {
const result = {
Expand All @@ -348,6 +348,14 @@ const approximateMatcher = {
}),
};

interface NumberMatchers extends jasmine.Matchers<number> {
isApproximately(expected: number): void;
not: NumberMatchers;
}
declare global {
function expect(actual: number): NumberMatchers;
}

const testCases = [
[MatColumnResizeModule, MatResizeTest, 'opt-in table-based mat-table'],
[MatColumnResizeModule, MatResizeOnPushTest, 'inside OnPush component'],
Expand Down Expand Up @@ -409,12 +417,8 @@ describe('Material Popover Edit', () => {
component.getOverlayThumbElement(2).classList.contains('mat-column-resize-overlay-thumb'),
).toBe(true);

(expect(component.getOverlayThumbElement(0).offsetHeight) as any).isApproximately(
headerRowHeight,
);
(expect(component.getOverlayThumbElement(2).offsetHeight) as any).isApproximately(
headerRowHeight,
);
expect(component.getOverlayThumbElement(0).offsetHeight).isApproximately(headerRowHeight);
expect(component.getOverlayThumbElement(2).offsetHeight).isApproximately(headerRowHeight);

component.beginColumnResizeWithMouse(0);

Expand All @@ -425,15 +429,11 @@ describe('Material Popover Edit', () => {
component.getOverlayThumbElement(2).classList.contains('mat-column-resize-overlay-thumb'),
).toBe(true);

(expect(component.getOverlayThumbElement(0).offsetHeight) as any).isApproximately(
tableHeight,
);
(expect(component.getOverlayThumbTopElement(0).offsetHeight) as any).isApproximately(
headerRowHeight,
);
(expect(component.getOverlayThumbElement(2).offsetHeight) as any).isApproximately(
expect(component.getOverlayThumbElement(0).offsetHeight).isApproximately(tableHeight);
expect(component.getOverlayThumbTopElement(0).offsetHeight).isApproximately(
headerRowHeight,
);
expect(component.getOverlayThumbElement(2).offsetHeight).isApproximately(headerRowHeight);

component.completeResizeWithMouseInProgress(0);
component.endHoverState();
Expand Down Expand Up @@ -462,31 +462,31 @@ describe('Material Popover Edit', () => {
let columnPositionDelta = component.getColumnOriginPosition(1) - initialColumnPosition;
// let nextColumnPositionDelta =
// component.getColumnOriginPosition(2) - initialNextColumnPosition;
(expect(thumbPositionDelta) as any).isApproximately(columnPositionDelta);
expect(thumbPositionDelta).isApproximately(columnPositionDelta);
// TODO: This was commented out after switching from the legacy table to the current
// MDC-based table. This failed by being inaccurate by several pixels.
// (expect(nextColumnPositionDelta) as any).isApproximately(columnPositionDelta);
// expect(nextColumnPositionDelta).isApproximately(columnPositionDelta);

// TODO: This was commented out after switching from the legacy table to the current
// MDC-based table. This failed by being inaccurate by several pixels.
// (expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 5);
(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 5);
// expect(component.getTableWidth()).isApproximately(initialTableWidth + 5);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 5);

component.updateResizeWithMouseInProgress(1);
fixture.detectChanges();
flush();

thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;
columnPositionDelta = component.getColumnOriginPosition(1) - initialColumnPosition;
(expect(thumbPositionDelta) as any).isApproximately(columnPositionDelta);
expect(thumbPositionDelta).isApproximately(columnPositionDelta);

(expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 1);
(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 1);
expect(component.getTableWidth()).isApproximately(initialTableWidth + 1);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 1);

component.completeResizeWithMouseInProgress(1);
flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 1);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 1);

component.endHoverState();
fixture.detectChanges();
Expand All @@ -508,23 +508,23 @@ describe('Material Popover Edit', () => {
flush();

let thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;
(expect(thumbPositionDelta) as any).isApproximately(5);
(expect(component.getColumnWidth(1)) as any).toBe(initialColumnWidth);
expect(thumbPositionDelta).isApproximately(5);
expect(component.getColumnWidth(1)).toBe(initialColumnWidth);

component.updateResizeWithMouseInProgress(1);
fixture.detectChanges();
flush();

thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;

(expect(component.getTableWidth()) as any).toBe(initialTableWidth);
(expect(component.getColumnWidth(1)) as any).toBe(initialColumnWidth);
expect(component.getTableWidth()).toBe(initialTableWidth);
expect(component.getColumnWidth(1)).toBe(initialColumnWidth);

component.completeResizeWithMouseInProgress(1);
flush();

(expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 1);
(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 1);
expect(component.getTableWidth()).isApproximately(initialTableWidth + 1);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 1);

component.endHoverState();
fixture.detectChanges();
Expand Down Expand Up @@ -562,18 +562,18 @@ describe('Material Popover Edit', () => {

let thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;
let columnPositionDelta = component.getColumnOriginPosition(1) - initialColumnPosition;
(expect(thumbPositionDelta) as any).isApproximately(columnPositionDelta);
expect(thumbPositionDelta).isApproximately(columnPositionDelta);

(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 5);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 5);
// TODO: This was commented out after switching from the legacy table to the current
// MDC-based table. This failed by being inaccurate by several pixels.
// (expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 5);
// expect(component.getTableWidth()).isApproximately(initialTableWidth + 5);

dispatchKeyboardEvent(document, 'keyup', ESCAPE);
flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth);
(expect(component.getTableWidth()) as any).isApproximately(initialTableWidth);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth);
expect(component.getTableWidth()).isApproximately(initialTableWidth);

component.endHoverState();
fixture.detectChanges();
Expand All @@ -582,7 +582,7 @@ describe('Material Popover Edit', () => {
it('notifies subscribers of a completed resize via ColumnResizeNotifier', fakeAsync(() => {
const initialColumnWidth = component.getColumnWidth(1);

let resize: ColumnSize | null = null;
let resize: ColumnSize | null = null as ColumnSize | null;
component.columnResize.columnResizeNotifier.resizeCompleted.subscribe(size => {
resize = size;
});
Expand All @@ -596,7 +596,7 @@ describe('Material Popover Edit', () => {
fixture.detectChanges();
flush();

expect(resize).toEqual({columnId: 'name', size: initialColumnWidth + 5} as any);
expect(resize).toEqual({columnId: 'name', size: initialColumnWidth + 5});

component.endHoverState();
fixture.detectChanges();
Expand Down Expand Up @@ -626,12 +626,12 @@ describe('Material Popover Edit', () => {

it('performs a column resize triggered via ColumnResizeNotifier', fakeAsync(() => {
// Pre-verify that we are not updating the size to the initial size.
(expect(component.getColumnWidth(1)) as any).not.isApproximately(173);
expect(component.getColumnWidth(1)).not.isApproximately(173);

component.columnResize.columnResizeNotifier.resize('name', 173);
flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(173);
expect(component.getColumnWidth(1)).isApproximately(173);
}));
});
}
Expand Down Expand Up @@ -660,13 +660,13 @@ describe('Material Popover Edit', () => {
}));

it('applies the persisted size', fakeAsync(() => {
(expect(component.getColumnWidth(1)).not as any).isApproximately(300);
expect(component.getColumnWidth(1)).not.isApproximately(300);

columnSizeStore.emitSize('theTable', 'name', 300);

flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(300);
expect(component.getColumnWidth(1)).isApproximately(300);
}));

it('persists the user-triggered size update', fakeAsync(() => {
Expand All @@ -689,7 +689,7 @@ describe('Material Popover Edit', () => {
const {tableId, columnId, sizePx} = columnSizeStore.setSizeCalls[0];
expect(tableId).toBe('theTable');
expect(columnId).toBe('name');
(expect(sizePx) as any).isApproximately(initialColumnWidth + 5);
expect(sizePx).isApproximately(initialColumnWidth + 5);
}));

it('persists the user-triggered size update (live updates off)', fakeAsync(() => {
Expand All @@ -714,7 +714,7 @@ describe('Material Popover Edit', () => {
const {tableId, columnId, sizePx} = columnSizeStore.setSizeCalls[0];
expect(tableId).toBe('theTable');
expect(columnId).toBe('name');
(expect(sizePx) as any).isApproximately(initialColumnWidth + 5);
expect(sizePx).isApproximately(initialColumnWidth + 5);
}));
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/material-luxon-adapter/adapter/luxon-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return this._useUTC ? LuxonDateTime.utc(options) : LuxonDateTime.local(options);
}

parse(value: any, parseFormat: string | string[]): LuxonDateTime | null {
parse(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {
const options: LuxonDateTimeOptions = this._getOptions();

if (typeof value == 'string' && value.length > 0) {
Expand Down Expand Up @@ -245,7 +245,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid DateTime and empty
* string into null. Returns an invalid date for all other values.
*/
override deserialize(value: any): LuxonDateTime | null {
override deserialize(value: unknown): LuxonDateTime | null {
const options = this._getOptions();
let date: LuxonDateTime | undefined;
if (value instanceof Date) {
Expand All @@ -263,7 +263,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return super.deserialize(value);
}

isDateInstance(obj: any): boolean {
isDateInstance(obj: unknown): obj is LuxonDateTime {
return obj instanceof LuxonDateTime;
}

Expand Down Expand Up @@ -315,7 +315,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return date.second;
}

override parseTime(value: any, parseFormat: string | string[]): LuxonDateTime | null {
override parseTime(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {
const result = this.parse(value, parseFormat);

if ((!result || !this.isValid(result)) && typeof value === 'string') {
Expand Down
8 changes: 4 additions & 4 deletions src/material-moment-adapter/adapter/moment-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return this._createMoment().locale(this.locale);
}

parse(value: any, parseFormat: string | string[]): Moment | null {
parse(value: unknown, parseFormat: string | string[]): Moment | null {
if (value && typeof value == 'string') {
return this._createMoment(value, parseFormat, this.locale);
}
Expand Down Expand Up @@ -223,7 +223,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid Moments and empty
* string into null. Returns an invalid date for all other values.
*/
override deserialize(value: any): Moment | null {
override deserialize(value: unknown): Moment | null {
let date;
if (value instanceof Date) {
date = this._createMoment(value).locale(this.locale);
Expand All @@ -243,7 +243,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return super.deserialize(value);
}

isDateInstance(obj: any): boolean {
isDateInstance(obj: unknown): obj is Moment {
return moment.isMoment(obj);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return date.seconds();
}

override parseTime(value: any, parseFormat: string | string[]): Moment | null {
override parseTime(value: unknown, parseFormat: string | string[]): Moment | null {
return this.parse(value, parseFormat);
}

Expand Down
Loading
Loading