Skip to content

Commit 5384550

Browse files
authored
build: enforce consistent readonly array type (#20290)
1 parent 92af5f1 commit 5384550

File tree

22 files changed

+47
-41
lines changed

22 files changed

+47
-41
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW, TAB} from '@angular/cdk/k
33
import {CdkTableModule} from '@angular/cdk/table';
44
import {dispatchKeyboardEvent} from '@angular/cdk/testing/private';
55
import {CommonModule} from '@angular/common';
6-
import {Component, Directive, ElementRef, Type, ViewChild} from '@angular/core';
6+
import {Component, Directive, ElementRef, ViewChild} from '@angular/core';
77
import {ComponentFixture, fakeAsync, flush, TestBed, tick, inject} from '@angular/core/testing';
88
import {FormsModule, NgForm} from '@angular/forms';
99
import {BidiModule, Direction} from '@angular/cdk/bidi';
@@ -359,12 +359,12 @@ class CdkTableInCell extends BaseTestComponent {
359359
}
360360
}
361361

362-
const testCases: ReadonlyArray<[Type<BaseTestComponent>, string]> = [
362+
const testCases = [
363363
[VanillaTableOutOfCell, 'Vanilla HTML table; edit defined outside of cell'],
364364
[VanillaTableInCell, 'Vanilla HTML table; edit defined within cell'],
365365
[CdkFlexTableInCell, 'Flex cdk-table; edit defined within cell'],
366366
[CdkTableInCell, 'Table cdk-table; edit defined within cell'],
367-
];
367+
] as const;
368368

369369
describe('CDK Popover Edit', () => {
370370
for (const [componentClass, label] of testCases) {
@@ -381,7 +381,7 @@ describe('CDK Popover Edit', () => {
381381
inject([OverlayContainer], (oc: OverlayContainer) => {
382382
overlayContainer = oc;
383383
})();
384-
fixture = TestBed.createComponent(componentClass);
384+
fixture = TestBed.createComponent<BaseTestComponent>(componentClass);
385385
component = fixture.componentInstance;
386386
fixture.detectChanges();
387387
tick(10);

src/cdk-experimental/selection/selection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class CdkSelection<T> implements OnInit, AfterContentChecked, CollectionV
9393
return;
9494
}
9595

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

9898
if (isDataSource(this._dataSource)) {
9999
dataStream = this._dataSource.connect(this);
@@ -219,4 +219,4 @@ export class CdkSelection<T> implements OnInit, AfterContentChecked, CollectionV
219219
}
220220

221221
type SelectAllState = 'all'|'none'|'partial';
222-
type TableDataSource<T> = DataSource<T>|Observable<ReadonlyArray<T>|T[]>|ReadonlyArray<T>|T[];
222+
type TableDataSource<T> = DataSource<T>|Observable<readonly T[]>|readonly T[];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {DataSource} from './data-source';
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ export class DropListRef<T = any> {
161161
private _previousSwap = {drag: null as DragRef | null, delta: 0, overlaps: false};
162162

163163
/** Draggable items in the container. */
164-
private _draggables: ReadonlyArray<DragRef> = [];
164+
private _draggables: readonly DragRef[] = [];
165165

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

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

415415
/** Gets the scrollable parents that are registered with this drop container. */
416-
getScrollableParents(): ReadonlyArray<HTMLElement> {
416+
getScrollableParents(): readonly HTMLElement[] {
417417
return this._scrollableElements;
418418
}
419419

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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[];
@@ -299,7 +299,7 @@ export class CdkVirtualForOf<T> implements
299299

300300
/** Swap out one `DataSource` for another. */
301301
private _changeDataSource(oldDs: DataSource<T> | null, newDs: DataSource<T> | null):
302-
Observable<T[] | ReadonlyArray<T>> {
302+
Observable<readonly T[]> {
303303

304304
if (oldDs) {
305305
oldDs.disconnect(this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import {ListRange} from '@angular/cdk/collections';
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/sticky-position-listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type StickySize = number|null|undefined;
1616
export type StickyOffset = number|null|undefined;
1717

1818
export interface StickyUpdate {
19-
elements?: ReadonlyArray<HTMLElement[]|undefined>;
19+
elements?: readonly (HTMLElement[]|undefined)[];
2020
offsets?: StickyOffset[];
2121
sizes: StickySize[];
2222
}

0 commit comments

Comments
 (0)