Skip to content

Commit 7275a3f

Browse files
committed
build: enforce consistent readonly array type
1 parent cb8de61 commit 7275a3f

File tree

20 files changed

+86
-83
lines changed

20 files changed

+86
-83
lines changed

src/cdk-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
import {BidiModule, Direction} from '@angular/cdk/bidi';
12
import {DataSource} from '@angular/cdk/collections';
2-
import {LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW, TAB} from '@angular/cdk/keycodes';
3+
import {DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, TAB, UP_ARROW} from '@angular/cdk/keycodes';
4+
import {OverlayContainer} from '@angular/cdk/overlay';
35
import {CdkTableModule} from '@angular/cdk/table';
46
import {dispatchKeyboardEvent} from '@angular/cdk/testing/private';
57
import {CommonModule} from '@angular/common';
6-
import {Component, Directive, ElementRef, Type, ViewChild} from '@angular/core';
7-
import {ComponentFixture, fakeAsync, flush, TestBed, tick, inject} from '@angular/core/testing';
8+
import {Component, Directive, ElementRef, ViewChild} from '@angular/core';
9+
import {ComponentFixture, fakeAsync, flush, inject, TestBed, tick} from '@angular/core/testing';
810
import {FormsModule, NgForm} from '@angular/forms';
9-
import {BidiModule, Direction} from '@angular/cdk/bidi';
10-
import {OverlayContainer} from '@angular/cdk/overlay';
1111
import {BehaviorSubject} from 'rxjs';
12-
1312
import {
1413
CdkPopoverEditColspan,
1514
CdkPopoverEditModule,
16-
HoverContentState,
1715
FormValueContainer,
16+
HoverContentState,
1817
PopoverEditClickOutBehavior,
1918
} from './index';
2019

@@ -359,12 +358,12 @@ class CdkTableInCell extends BaseTestComponent {
359358
}
360359
}
361360

362-
const testCases: ReadonlyArray<[Type<BaseTestComponent>, string]> = [
361+
const testCases = [
363362
[VanillaTableOutOfCell, 'Vanilla HTML table; edit defined outside of cell'],
364363
[VanillaTableInCell, 'Vanilla HTML table; edit defined within cell'],
365364
[CdkFlexTableInCell, 'Flex cdk-table; edit defined within cell'],
366365
[CdkTableInCell, 'Table cdk-table; edit defined within cell'],
367-
];
366+
] as const;
368367

369368
describe('CDK Popover Edit', () => {
370369
for (const [componentClass, label] of testCases) {
@@ -381,7 +380,7 @@ describe('CDK Popover Edit', () => {
381380
inject([OverlayContainer], (oc: OverlayContainer) => {
382381
overlayContainer = oc;
383382
})();
384-
fixture = TestBed.createComponent(componentClass);
383+
fixture = TestBed.createComponent<BaseTestComponent>(componentClass);
385384
component = fixture.componentInstance;
386385
fixture.detectChanges();
387386
tick(10);

src/cdk/collections/array-data-source.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Observable, isObservable, of as observableOf} from 'rxjs';
9+
import {isObservable, Observable, of as observableOf} from 'rxjs';
1010
import {DataSource} from './data-source';
1111

1212

1313
/** DataSource wrapper for a native array. */
1414
export class ArrayDataSource<T> extends DataSource<T> {
15-
constructor(private _data: T[] | ReadonlyArray<T> | Observable<T[] | ReadonlyArray<T>>) {
15+
constructor(private _data: readonly T[] | Observable<readonly T[]>) {
1616
super();
1717
}
1818

19-
connect(): Observable<T[] | ReadonlyArray<T>> {
19+
connect(): Observable<readonly T[]> {
2020
return isObservable(this._data) ? this._data : observableOf(this._data);
2121
}
2222

src/cdk/collections/data-source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export abstract class DataSource<T> {
1818
* data source.
1919
* @returns Observable that emits a new value when the data changes.
2020
*/
21-
abstract connect(collectionViewer: CollectionViewer): Observable<T[] | ReadonlyArray<T>>;
21+
abstract connect(collectionViewer: CollectionViewer): Observable<readonly T[]>;
2222

2323
/**
2424
* Disconnects a collection viewer (such as a data-table) from this data source. Can be used

src/cdk/drag-drop/drop-list-ref.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ElementRef, NgZone} from '@angular/core';
109
import {Direction} from '@angular/cdk/bidi';
1110
import {coerceElement} from '@angular/cdk/coercion';
12-
import {ViewportRuler} from '@angular/cdk/scrolling';
1311
import {_getShadowRoot} from '@angular/cdk/platform';
14-
import {Subject, Subscription, interval, animationFrameScheduler} from 'rxjs';
12+
import {ViewportRuler} from '@angular/cdk/scrolling';
13+
import {ElementRef, NgZone} from '@angular/core';
14+
import {animationFrameScheduler, interval, Subject, Subscription} from 'rxjs';
1515
import {takeUntil} from 'rxjs/operators';
16-
import {moveItemInArray} from './drag-utils';
17-
import {DragDropRegistry} from './drag-drop-registry';
18-
import {DragRefInternal as DragRef, Point} from './drag-ref';
1916
import {
20-
isPointerNearClientRect,
2117
adjustClientRect,
2218
getMutableClientRect,
2319
isInsideClientRect,
20+
isPointerNearClientRect,
2421
} from './client-rect';
25-
import {ParentPositionTracker} from './parent-position-tracker';
22+
import {DragDropRegistry} from './drag-drop-registry';
23+
import {DragRefInternal as DragRef, Point} from './drag-ref';
2624
import {DragCSSStyleDeclaration} from './drag-styling';
25+
import {moveItemInArray} from './drag-utils';
26+
import {ParentPositionTracker} from './parent-position-tracker';
2727

2828
/**
2929
* Proximity, as a ratio to width/height, at which a
@@ -160,10 +160,10 @@ export class DropListRef<T = any> {
160160
private _previousSwap = {drag: null as DragRef | null, delta: 0, overlaps: false};
161161

162162
/** Draggable items in the container. */
163-
private _draggables: ReadonlyArray<DragRef>;
163+
private _draggables: readonly DragRef[];
164164

165165
/** Drop lists that are connected to the current one. */
166-
private _siblings: ReadonlyArray<DropListRef> = [];
166+
private _siblings: readonly DropListRef[] = [];
167167

168168
/** Direction in which the list is oriented. */
169169
private _orientation: 'horizontal' | 'vertical' = 'vertical';
@@ -427,7 +427,7 @@ export class DropListRef<T = any> {
427427
}
428428

429429
/** Gets the scrollable parents that are registered with this drop container. */
430-
getScrollableParents(): ReadonlyArray<HTMLElement> {
430+
getScrollableParents(): readonly HTMLElement[] {
431431
return this._scrollableElements;
432432
}
433433

src/cdk/drag-drop/parent-position-tracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {ViewportRuler} from '@angular/cdk/scrolling';
10-
import {getMutableClientRect, adjustClientRect} from './client-rect';
10+
import {adjustClientRect, getMutableClientRect} from './client-rect';
1111

1212
/** Object holding the scroll position of something. */
1313
interface ScrollPosition {
@@ -31,7 +31,7 @@ export class ParentPositionTracker {
3131
}
3232

3333
/** Caches the positions. Should be called at the beginning of a drag sequence. */
34-
cache(elements: HTMLElement[] | ReadonlyArray<HTMLElement>) {
34+
cache(elements: readonly HTMLElement[]) {
3535
this.clear();
3636
this.positions.set(this._document, {
3737
scrollPosition: this._viewportRuler.getViewportScrollPosition(),

src/cdk/schematics/update-tool/utils/decorators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface NgDecorator {
2424
* (e.g. "@angular/core") from a list of decorators.
2525
*/
2626
export function getAngularDecorators(
27-
typeChecker: ts.TypeChecker, decorators: ReadonlyArray<ts.Decorator>): NgDecorator[] {
27+
typeChecker: ts.TypeChecker, decorators: readonly ts.Decorator[]): readonly NgDecorator[] {
2828
return decorators.map(node => ({node, importData: getCallDecoratorImport(typeChecker, node)}))
2929
.filter(({importData}) => importData && importData.moduleName.startsWith('@angular/'))
3030
.map(

src/cdk/scrolling/virtual-for-of.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
910
import {
1011
ArrayDataSource,
1112
CollectionViewer,
1213
DataSource,
13-
ListRange,
1414
isDataSource,
15+
ListRange,
1516
_RecycleViewRepeaterStrategy,
16-
_VIEW_REPEATER_STRATEGY,
1717
_ViewRepeaterItemInsertArgs,
18+
_VIEW_REPEATER_STRATEGY,
1819
} from '@angular/cdk/collections';
1920
import {
2021
Directive,
@@ -34,8 +35,7 @@ import {
3435
TrackByFunction,
3536
ViewContainerRef,
3637
} from '@angular/core';
37-
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
38-
import {Observable, Subject, of as observableOf, isObservable} from 'rxjs';
38+
import {isObservable, Observable, of as observableOf, Subject} from 'rxjs';
3939
import {pairwise, shareReplay, startWith, switchMap, takeUntil} from 'rxjs/operators';
4040
import {CdkVirtualScrollRepeater} from './virtual-scroll-repeater';
4141
import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
@@ -151,7 +151,7 @@ export class CdkVirtualForOf<T> implements
151151
}
152152

153153
/** Emits whenever the data in the current DataSource changes. */
154-
dataStream: Observable<T[] | ReadonlyArray<T>> = this._dataSourceChanges
154+
dataStream: Observable<readonly T[]> = this._dataSourceChanges
155155
.pipe(
156156
// Start off with null `DataSource`.
157157
startWith(null!),
@@ -168,7 +168,7 @@ export class CdkVirtualForOf<T> implements
168168
private _differ: IterableDiffer<T> | null = null;
169169

170170
/** The most recent data emitted from the DataSource. */
171-
private _data: T[] | ReadonlyArray<T>;
171+
private _data: readonly T[];
172172

173173
/** The currently rendered items. */
174174
private _renderedItems: T[];
@@ -294,7 +294,7 @@ export class CdkVirtualForOf<T> implements
294294

295295
/** Swap out one `DataSource` for another. */
296296
private _changeDataSource(oldDs: DataSource<T> | null, newDs: DataSource<T> | null):
297-
Observable<T[] | ReadonlyArray<T>> {
297+
Observable<readonly T[]> {
298298

299299
if (oldDs) {
300300
oldDs.disconnect(this);

src/cdk/scrolling/virtual-scroll-repeater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Observable} from 'rxjs';
109
import {ListRange} from '@angular/cdk/collections';
10+
import {Observable} from 'rxjs';
1111

1212
/**
1313
* An item to be repeated by the VirtualScrollViewport
1414
*/
1515
export interface CdkVirtualScrollRepeater<T> {
16-
dataStream: Observable<T[] | ReadonlyArray<T>>;
16+
dataStream: Observable<readonly T[]>;
1717
measureRangeSize(range: ListRange, orientation: 'horizontal' | 'vertical'): number;
1818
}

src/cdk/table/table.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {
1212
CollectionViewer,
1313
DataSource,
14-
_DisposeViewRepeaterStrategy,
1514
isDataSource,
16-
_VIEW_REPEATER_STRATEGY,
15+
_DisposeViewRepeaterStrategy,
1716
_ViewRepeater,
1817
_ViewRepeaterItemChange,
1918
_ViewRepeaterItemInsertArgs,
2019
_ViewRepeaterOperation,
20+
_VIEW_REPEATER_STRATEGY,
2121
} from '@angular/cdk/collections';
2222
import {Platform} from '@angular/cdk/platform';
2323
import {DOCUMENT} from '@angular/common';
@@ -90,7 +90,7 @@ export interface RowOutlet {
9090
* @docs-private
9191
*/
9292
type CdkTableDataSourceInput<T> =
93-
DataSource<T>|Observable<ReadonlyArray<T>|T[]>|ReadonlyArray<T>|T[];
93+
readonly T[]|DataSource<T>|Observable<readonly T[]>;
9494

9595
/**
9696
* Provides a handle for the table to grab the view container's ng-container to insert data rows.
@@ -207,7 +207,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
207207
private _document: Document;
208208

209209
/** Latest data provided by the data source. */
210-
protected _data: T[]|ReadonlyArray<T>;
210+
protected _data: readonly T[];
211211

212212
/** Subject that emits when the component has been destroyed. */
213213
private _onDestroy = new Subject<void>();
@@ -875,7 +875,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
875875
return;
876876
}
877877

878-
let dataStream: Observable<T[]|ReadonlyArray<T>>|undefined;
878+
let dataStream: Observable<readonly T[]>|undefined;
879879

880880
if (isDataSource(this.dataSource)) {
881881
dataStream = this.dataSource.connect(this);

src/cdk/tree/tree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest
198198

199199
/** Set up a subscription for the data provided by the data source. */
200200
private _observeRenderChanges() {
201-
let dataStream: Observable<T[] | ReadonlyArray<T>> | undefined;
201+
let dataStream: Observable<readonly T[]> | undefined;
202202

203203
if (isDataSource(this._dataSource)) {
204204
dataStream = this._dataSource.connect(this);
@@ -217,7 +217,7 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest
217217
}
218218

219219
/** Check for changes made in the data and render each change (node added/removed/moved). */
220-
renderNodeChanges(data: T[] | ReadonlyArray<T>, dataDiffer: IterableDiffer<T> = this._dataDiffer,
220+
renderNodeChanges(data: readonly T[], dataDiffer: IterableDiffer<T> = this._dataDiffer,
221221
viewContainer: ViewContainerRef = this._nodeOutlet.viewContainer,
222222
parentData?: T) {
223223
const changes = dataDiffer.diff(data);

src/components-examples/material/chips/chips-input/chips-input-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ChipsInputExample {
1919
selectable = true;
2020
removable = true;
2121
addOnBlur = true;
22-
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
22+
readonly separatorKeysCodes = [ENTER, COMMA];
2323
fruits: Fruit[] = [
2424
{name: 'Lemon'},
2525
{name: 'Lime'},

src/material-experimental/column-resize/column-resize.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
import {ColumnSize} from '@angular/cdk-experimental/column-resize';
2+
import {BidiModule} from '@angular/cdk/bidi';
3+
import {DataSource} from '@angular/cdk/collections';
4+
import {ESCAPE} from '@angular/cdk/keycodes';
5+
import {OverlayContainer} from '@angular/cdk/overlay';
6+
import {dispatchKeyboardEvent} from '@angular/cdk/testing/private';
17
import {
8+
ChangeDetectionStrategy,
29
Component,
310
Directive,
411
ElementRef,
5-
Type,
612
ViewChild,
7-
ChangeDetectionStrategy,
813
} from '@angular/core';
9-
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, inject} from '@angular/core/testing';
10-
import {BidiModule} from '@angular/cdk/bidi';
11-
import {DataSource} from '@angular/cdk/collections';
12-
import {dispatchKeyboardEvent} from '@angular/cdk/testing/private';
13-
import {ESCAPE} from '@angular/cdk/keycodes';
14-
import {OverlayContainer} from '@angular/cdk/overlay';
14+
import {ComponentFixture, fakeAsync, flushMicrotasks, inject, TestBed} from '@angular/core/testing';
1515
import {MatTableModule} from '@angular/material/table';
1616
import {BehaviorSubject} from 'rxjs';
17-
18-
import {ColumnSize} from '@angular/cdk-experimental/column-resize';
17+
import {AbstractMatColumnResize} from './column-resize-directives/common';
1918
import {
2019
MatColumnResize,
2120
MatColumnResizeFlex,
@@ -24,7 +23,6 @@ import {
2423
MatDefaultEnabledColumnResizeFlex,
2524
MatDefaultEnabledColumnResizeModule,
2625
} from './index';
27-
import {AbstractMatColumnResize} from './column-resize-directives/common';
2826

2927
function getDefaultEnabledDirectiveStrings() {
3028
return {
@@ -322,7 +320,7 @@ const approximateMatcher = {
322320
})
323321
};
324322

325-
const testCases: ReadonlyArray<[Type<object>, Type<BaseTestComponent>, string]> = [
323+
const testCases = [
326324
[MatColumnResizeModule, MatResizeTest, 'opt-in table-based mat-table'],
327325
[MatColumnResizeModule, MatResizeOnPushTest, 'inside OnPush component'],
328326
[MatColumnResizeModule, MatResizeFlexTest, 'opt-in flex-based mat-table'],
@@ -342,7 +340,7 @@ const testCases: ReadonlyArray<[Type<object>, Type<BaseTestComponent>, string]>
342340
MatDefaultEnabledColumnResizeModule, MatResizeDefaultFlexRtlTest,
343341
'default enabled rtl flex-based mat-table'
344342
],
345-
];
343+
] as const;
346344

347345
describe('Material Popover Edit', () => {
348346
for (const [resizeModule, componentClass, label] of testCases) {

0 commit comments

Comments
 (0)