From 264c20d19667074af9981d0de86e67fea4efa0d8 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 15 Jun 2020 16:09:08 +0200 Subject: [PATCH] build: enforce consistent array types (#19640) Adds some linting that we consistently use `T[]` instead of `Array`. --- .../popover-edit/edit-event-dispatcher.ts | 2 +- src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts | 8 ++++---- .../a11y/focus-trap/event-listener-inert-strategy.spec.ts | 6 +++--- src/cdk/overlay/overlay-config.ts | 2 +- src/cdk/table/sticky-styler.ts | 2 +- src/google-maps/google-map/google-map.ts | 2 +- src/material-experimental/mdc-chips/chip-grid.ts | 2 +- .../mdc-progress-bar/progress-bar.spec.ts | 2 +- src/material/progress-bar/progress-bar.spec.ts | 2 +- src/material/select/select.spec.ts | 2 +- src/material/tooltip/tooltip.spec.ts | 2 +- tools/public_api_guard/google-maps/google-maps.d.ts | 2 +- tslint.json | 1 + 13 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/cdk-experimental/popover-edit/edit-event-dispatcher.ts b/src/cdk-experimental/popover-edit/edit-event-dispatcher.ts index 9c763d154d73..c9d79fa6a2b8 100644 --- a/src/cdk-experimental/popover-edit/edit-event-dispatcher.ts +++ b/src/cdk-experimental/popover-edit/edit-event-dispatcher.ts @@ -274,7 +274,7 @@ export class EditEventDispatcher { } } -function computeHoverContentState([firstRow, lastRow, activeRow, hoverRow]: Array): +function computeHoverContentState([firstRow, lastRow, activeRow, hoverRow]: (Element|null)[]): Map { const hoverContentState = new Map(); diff --git a/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts b/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts index c810714b4a8f..f847894e6e2a 100644 --- a/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts +++ b/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component, ElementRef, Type, ViewChild} from '@angular/core'; +import {AfterViewInit, Component, ElementRef, Type, ViewChild, Provider} from '@angular/core'; import {ComponentFixture, TestBed} from '@angular/core/testing'; import { A11yModule, @@ -11,7 +11,7 @@ import { import {FocusTrapManager} from './focus-trap-manager'; describe('ConfigurableFocusTrap', () => { - let providers: Array; + let providers: Provider[]; describe('with FocusTrapInertStrategy', () => { let mockInertStrategy: FocusTrapInertStrategy; @@ -88,8 +88,8 @@ describe('ConfigurableFocusTrap', () => { }); }); -function createComponent(componentType: Type, providers: Array = [] - ): ComponentFixture { +function createComponent(componentType: Type, providers: Provider[] = []): + ComponentFixture { TestBed.configureTestingModule({ imports: [A11yModule], declarations: [componentType], diff --git a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts index 5cad94571c70..61be797a67ef 100644 --- a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts +++ b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component, ElementRef, Type, ViewChild} from '@angular/core'; +import {AfterViewInit, Component, ElementRef, Type, ViewChild, Provider} from '@angular/core'; import {ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing'; import {patchElementFocus} from '@angular/cdk/testing/private'; import { @@ -58,8 +58,8 @@ describe('EventListenerFocusTrapInertStrategy', () => { }); -function createComponent(componentType: Type, providers: Array = [] - ): ComponentFixture { +function createComponent(componentType: Type, providers: Provider[] = []): + ComponentFixture { TestBed.configureTestingModule({ imports: [A11yModule], declarations: [componentType], diff --git a/src/cdk/overlay/overlay-config.ts b/src/cdk/overlay/overlay-config.ts index 9f5fc15467fa..f665e2164921 100644 --- a/src/cdk/overlay/overlay-config.ts +++ b/src/cdk/overlay/overlay-config.ts @@ -65,7 +65,7 @@ export class OverlayConfig { // loses the array generic type in the `for of`. But we *also* have to use `Array` because // typescript won't iterate over an `Iterable` unless you compile with `--downlevelIteration` const configKeys = - Object.keys(config) as Iterable & Array; + Object.keys(config) as Iterable & (keyof OverlayConfig)[]; for (const key of configKeys) { if (config[key] !== undefined) { // TypeScript, as of version 3.5, sees the left-hand-side of this expression diff --git a/src/cdk/table/sticky-styler.ts b/src/cdk/table/sticky-styler.ts index 05f6bd35bd96..73ffced0c888 100644 --- a/src/cdk/table/sticky-styler.ts +++ b/src/cdk/table/sticky-styler.ts @@ -224,7 +224,7 @@ export class StickyStyler { // Use `Iterable` instead of `Array` because TypeScript, as of 3.6.3, // loses the array generic type in the `for of`. But we *also* have to use `Array` because // typescript won't iterate over an `Iterable` unless you compile with `--downlevelIteration` - for (const dir of STICKY_DIRECTIONS as Iterable & Array) { + for (const dir of STICKY_DIRECTIONS as Iterable & StickyDirection[]) { if (element.style[dir]) { zIndex += zIndexIncrements[dir]; } diff --git a/src/google-maps/google-map/google-map.ts b/src/google-maps/google-map/google-map.ts index 31fa731abc70..9f8e39fb9eff 100644 --- a/src/google-maps/google-map/google-map.ts +++ b/src/google-maps/google-map/google-map.ts @@ -408,7 +408,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { * See * https://developers.google.com/maps/documentation/javascript/reference/map#Map.controls */ - get controls(): Array> { + get controls(): google.maps.MVCArray[] { this._assertInitialized(); return this.googleMap.controls; } diff --git a/src/material-experimental/mdc-chips/chip-grid.ts b/src/material-experimental/mdc-chips/chip-grid.ts index 3bf25a7a3af5..554c143d7ecc 100644 --- a/src/material-experimental/mdc-chips/chip-grid.ts +++ b/src/material-experimental/mdc-chips/chip-grid.ts @@ -204,7 +204,7 @@ export class MatChipGrid extends _MatChipGridMixinBase implements AfterContentIn set value(value: any) { this._value = value; } - protected _value: Array = []; + protected _value: any[] = []; /** An object used to control when error messages are shown. */ @Input() errorStateMatcher: ErrorStateMatcher; diff --git a/src/material-experimental/mdc-progress-bar/progress-bar.spec.ts b/src/material-experimental/mdc-progress-bar/progress-bar.spec.ts index ae94cbb7dff5..699fb37dee69 100644 --- a/src/material-experimental/mdc-progress-bar/progress-bar.spec.ts +++ b/src/material-experimental/mdc-progress-bar/progress-bar.spec.ts @@ -8,7 +8,7 @@ import {MatProgressBar} from './progress-bar'; describe('MDC-based MatProgressBar', () => { function createComponent(componentType: Type, - imports?: Array>): ComponentFixture { + imports?: Type<{}>[]): ComponentFixture { TestBed.configureTestingModule({ imports: imports || [MatProgressBarModule], declarations: [componentType] diff --git a/src/material/progress-bar/progress-bar.spec.ts b/src/material/progress-bar/progress-bar.spec.ts index b465201c3e0f..47e28029b4d8 100644 --- a/src/material/progress-bar/progress-bar.spec.ts +++ b/src/material/progress-bar/progress-bar.spec.ts @@ -10,7 +10,7 @@ describe('MatProgressBar', () => { let fakePath: string; function createComponent(componentType: Type, - imports?: Array>): ComponentFixture { + imports?: Type<{}>[]): ComponentFixture { fakePath = '/fake-path'; TestBed.configureTestingModule({ diff --git a/src/material/select/select.spec.ts b/src/material/select/select.spec.ts index cdcecb4e3b9c..93eff51eac5d 100644 --- a/src/material/select/select.spec.ts +++ b/src/material/select/select.spec.ts @@ -941,7 +941,7 @@ describe('MatSelect', () => { describe('for options', () => { let fixture: ComponentFixture; let trigger: HTMLElement; - let options: Array; + let options: HTMLElement[]; beforeEach(fakeAsync(() => { fixture = TestBed.createComponent(BasicSelect); diff --git a/src/material/tooltip/tooltip.spec.ts b/src/material/tooltip/tooltip.spec.ts index bd07d16d2609..61bf22c03c63 100644 --- a/src/material/tooltip/tooltip.spec.ts +++ b/src/material/tooltip/tooltip.spec.ts @@ -1168,7 +1168,7 @@ class OnPushTooltipDemo { `, }) class DynamicTooltipsDemo { - tooltips: Array = []; + tooltips: string[] = []; } @Component({ diff --git a/tools/public_api_guard/google-maps/google-maps.d.ts b/tools/public_api_guard/google-maps/google-maps.d.ts index 27dc742e96df..f62403f7838f 100644 --- a/tools/public_api_guard/google-maps/google-maps.d.ts +++ b/tools/public_api_guard/google-maps/google-maps.d.ts @@ -3,7 +3,7 @@ export declare class GoogleMap implements OnChanges, OnInit, OnDestroy { boundsChanged: Observable; set center(center: google.maps.LatLngLiteral | google.maps.LatLng); centerChanged: Observable; - get controls(): Array>; + get controls(): google.maps.MVCArray[]; get data(): google.maps.Data; googleMap?: google.maps.Map; headingChanged: Observable; diff --git a/tslint.json b/tslint.json index a3913b0ab29c..581ff2108f7a 100644 --- a/tslint.json +++ b/tslint.json @@ -97,6 +97,7 @@ "jsdoc-format": [true, "check-multiline-start"], "no-duplicate-imports": true, "await-promise": true, + "array-type": [true, "array"], // Codelyzer "template-banana-in-box": true,