Skip to content

Commit

Permalink
build: enforce consistent array types (#19640)
Browse files Browse the repository at this point in the history
Adds some linting that we consistently use `T[]` instead of `Array<T>`.
  • Loading branch information
crisbeto authored Jun 15, 2020
1 parent 17a7a97 commit 264c20d
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/cdk-experimental/popover-edit/edit-event-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class EditEventDispatcher {
}
}

function computeHoverContentState([firstRow, lastRow, activeRow, hoverRow]: Array<Element|null>):
function computeHoverContentState([firstRow, lastRow, activeRow, hoverRow]: (Element|null)[]):
Map<Element, HoverContentState> {
const hoverContentState = new Map<Element, HoverContentState>();

Expand Down
8 changes: 4 additions & 4 deletions src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,7 +11,7 @@ import {
import {FocusTrapManager} from './focus-trap-manager';

describe('ConfigurableFocusTrap', () => {
let providers: Array<Object>;
let providers: Provider[];

describe('with FocusTrapInertStrategy', () => {
let mockInertStrategy: FocusTrapInertStrategy;
Expand Down Expand Up @@ -88,8 +88,8 @@ describe('ConfigurableFocusTrap', () => {
});
});

function createComponent<T>(componentType: Type<T>, providers: Array<Object> = []
): ComponentFixture<T> {
function createComponent<T>(componentType: Type<T>, providers: Provider[] = []):
ComponentFixture<T> {
TestBed.configureTestingModule({
imports: [A11yModule],
declarations: [componentType],
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -58,8 +58,8 @@ describe('EventListenerFocusTrapInertStrategy', () => {

});

function createComponent<T>(componentType: Type<T>, providers: Array<Object> = []
): ComponentFixture<T> {
function createComponent<T>(componentType: Type<T>, providers: Provider[] = []):
ComponentFixture<T> {
TestBed.configureTestingModule({
imports: [A11yModule],
declarations: [componentType],
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/overlay/overlay-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<keyof OverlayConfig> & Array<keyof OverlayConfig>;
Object.keys(config) as Iterable<keyof OverlayConfig> & (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
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/table/sticky-styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StickyDirection> & Array<StickyDirection>) {
for (const dir of STICKY_DIRECTIONS as Iterable<StickyDirection> & StickyDirection[]) {
if (element.style[dir]) {
zIndex += zIndexIncrements[dir];
}
Expand Down
2 changes: 1 addition & 1 deletion src/google-maps/google-map/google-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<google.maps.MVCArray<Node>> {
get controls(): google.maps.MVCArray<Node>[] {
this._assertInitialized();
return this.googleMap.controls;
}
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class MatChipGrid extends _MatChipGridMixinBase implements AfterContentIn
set value(value: any) {
this._value = value;
}
protected _value: Array<any> = [];
protected _value: any[] = [];

/** An object used to control when error messages are shown. */
@Input() errorStateMatcher: ErrorStateMatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MatProgressBar} from './progress-bar';

describe('MDC-based MatProgressBar', () => {
function createComponent<T>(componentType: Type<T>,
imports?: Array<Type<{}>>): ComponentFixture<T> {
imports?: Type<{}>[]): ComponentFixture<T> {
TestBed.configureTestingModule({
imports: imports || [MatProgressBarModule],
declarations: [componentType]
Expand Down
2 changes: 1 addition & 1 deletion src/material/progress-bar/progress-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('MatProgressBar', () => {
let fakePath: string;

function createComponent<T>(componentType: Type<T>,
imports?: Array<Type<{}>>): ComponentFixture<T> {
imports?: Type<{}>[]): ComponentFixture<T> {
fakePath = '/fake-path';

TestBed.configureTestingModule({
Expand Down
2 changes: 1 addition & 1 deletion src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ describe('MatSelect', () => {
describe('for options', () => {
let fixture: ComponentFixture<BasicSelect>;
let trigger: HTMLElement;
let options: Array<HTMLElement>;
let options: HTMLElement[];

beforeEach(fakeAsync(() => {
fixture = TestBed.createComponent(BasicSelect);
Expand Down
2 changes: 1 addition & 1 deletion src/material/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ class OnPushTooltipDemo {
</button>`,
})
class DynamicTooltipsDemo {
tooltips: Array<string> = [];
tooltips: string[] = [];
}

@Component({
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/google-maps/google-maps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export declare class GoogleMap implements OnChanges, OnInit, OnDestroy {
boundsChanged: Observable<void>;
set center(center: google.maps.LatLngLiteral | google.maps.LatLng);
centerChanged: Observable<void>;
get controls(): Array<google.maps.MVCArray<Node>>;
get controls(): google.maps.MVCArray<Node>[];
get data(): google.maps.Data;
googleMap?: google.maps.Map;
headingChanged: Observable<void>;
Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 264c20d

Please sign in to comment.