Skip to content

Commit c79f5b7

Browse files
authored
refactor: adding types to sortedColumn (#1466)
1 parent 60bdd98 commit c79f5b7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

projects/components/src/table/table.component.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ export class TableComponent
309309
public readonly columnConfigsChange: EventEmitter<TableColumnConfig[]> = new EventEmitter<TableColumnConfig[]>();
310310

311311
@Output()
312-
public readonly sortChange: EventEmitter<SortedColumn> = new EventEmitter<SortedColumn>();
312+
public readonly sortChange: EventEmitter<SortedColumn<TableColumnConfig>> = new EventEmitter<
313+
SortedColumn<TableColumnConfig>
314+
>();
313315

314316
@ViewChild(PaginatorComponent)
315317
public paginator?: PaginatorComponent;
@@ -390,7 +392,7 @@ export class TableComponent
390392
combineLatest([this.activatedRoute.queryParamMap, this.columnConfigs$])
391393
.pipe(
392394
map(([queryParamMap, columns]) => this.sortDataFromUrl(queryParamMap, columns)),
393-
filter((sort): sort is Required<SortedColumn> => sort !== undefined)
395+
filter((sort): sort is Required<SortedColumn<TableColumnConfigExtended>> => sort !== undefined)
394396
)
395397
.subscribe(sort => this.updateSort(sort));
396398
}
@@ -541,7 +543,7 @@ export class TableComponent
541543

542544
public onSortChange(direction: TableSortDirection, columnConfig: TableColumnConfigExtended): void {
543545
if (TableCdkColumnUtil.isColumnSortable(columnConfig)) {
544-
const sortedColumn: SortedColumn = {
546+
const sortedColumn: SortedColumn<TableColumnConfigExtended> = {
545547
column: columnConfig,
546548
direction: direction
547549
};
@@ -629,7 +631,7 @@ export class TableComponent
629631
return new TableCdkDataSource(this, this, this, this, this, this.paginator);
630632
}
631633

632-
private updateSort(sort: SortedColumn): void {
634+
private updateSort(sort: SortedColumn<TableColumnConfigExtended>): void {
633635
sort.column.sort = sort.direction;
634636
this.columnStateSubject.next(sort.column);
635637
}
@@ -764,7 +766,10 @@ export class TableComponent
764766
};
765767
}
766768

767-
private sortDataFromUrl(params: ParamMap, columns: TableColumnConfigExtended[]): Required<SortedColumn> | undefined {
769+
private sortDataFromUrl(
770+
params: ParamMap,
771+
columns: TableColumnConfigExtended[]
772+
): Required<SortedColumn<TableColumnConfigExtended>> | undefined {
768773
if (!this.syncWithUrl) {
769774
return undefined;
770775
}
@@ -781,8 +786,8 @@ export class TableComponent
781786
}
782787
}
783788

784-
export interface SortedColumn {
785-
column: TableColumnConfigExtended;
789+
export interface SortedColumn<TCol extends TableColumnConfig> {
790+
column: TCol;
786791
direction?: TableSortDirection;
787792
}
788793

0 commit comments

Comments
 (0)