Skip to content

Commit 471813c

Browse files
authored
refactor(tree): Make type parameters consistent in Table schema APIs (#24529)
Most of the types are expressed in terms of the schema types, but a couple of interfaces were previously expressed in terms of derived types. This updates the code such that all of the types are consistently expressed in terms of the schema types.
1 parent 39aad76 commit 471813c

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

packages/dds/tree/src/tableSchema.ts

+22-25
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,8 @@ export namespace System_TableSchema {
428428
type Scope = ScopedSchemaName<TInputScope, typeof tableSchemaFactorySubScope>;
429429

430430
type CellValueType = TreeNodeFromImplicitAllowedTypes<TCellSchema>;
431-
type CellInsertableType = InsertableTreeNodeFromImplicitAllowedTypes<TCellSchema>;
432-
433431
type ColumnValueType = TreeNodeFromImplicitAllowedTypes<TColumnSchema>;
434-
type ColumnInsertableType = InsertableTreeNodeFromImplicitAllowedTypes<TColumnSchema>;
435-
436432
type RowValueType = TreeNodeFromImplicitAllowedTypes<TRowSchema>;
437-
type RowInsertableType = InsertableTreeNodeFromImplicitAllowedTypes<TRowSchema>;
438433

439434
/**
440435
* {@link Table} fields.
@@ -488,7 +483,7 @@ export namespace System_TableSchema {
488483
public insertColumn({
489484
column,
490485
index,
491-
}: TableSchema.InsertColumnParameters<ColumnInsertableType>): ColumnValueType {
486+
}: TableSchema.InsertColumnParameters<TColumnSchema>): ColumnValueType {
492487
if (index === undefined) {
493488
// TypeScript is unable to narrow the types correctly here, hence the cast.
494489
// See: https://github.com/microsoft/TypeScript/issues/52144
@@ -508,7 +503,7 @@ export namespace System_TableSchema {
508503
public insertRows({
509504
index,
510505
rows,
511-
}: TableSchema.InsertRowsParameters<RowInsertableType>): RowValueType[] {
506+
}: TableSchema.InsertRowsParameters<TRowSchema>): RowValueType[] {
512507
if (index === undefined) {
513508
// TypeScript is unable to narrow the types correctly here, hence the cast.
514509
// See: https://github.com/microsoft/TypeScript/issues/52144
@@ -525,7 +520,7 @@ export namespace System_TableSchema {
525520
return rows as unknown as RowValueType[];
526521
}
527522

528-
public setCell({ key, cell }: TableSchema.SetCellParameters<CellInsertableType>): void {
523+
public setCell({ key, cell }: TableSchema.SetCellParameters<TCellSchema>): void {
529524
const { columnId, rowId } = key;
530525
const row = this.getRow(rowId);
531526
if (row !== undefined) {
@@ -708,7 +703,7 @@ export namespace TableSchema {
708703
* @sealed @internal
709704
*/
710705
export interface IRow<
711-
TCell extends ImplicitAllowedTypes,
706+
TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
712707
TProps extends ImplicitAnnotatedFieldSchema = ImplicitAnnotatedFieldSchema,
713708
> {
714709
/**
@@ -835,7 +830,9 @@ export namespace TableSchema {
835830
* {@link TableSchema.ITable.insertColumn} parameters.
836831
* @internal
837832
*/
838-
export interface InsertColumnParameters<TInsertableColumn> {
833+
export interface InsertColumnParameters<
834+
TColumn extends ImplicitAllowedTypes = ImplicitAllowedTypes,
835+
> {
839836
/**
840837
* The index at which to insert the new column.
841838
* @remarks If not provided, the column will be appended to the end of the table.
@@ -845,14 +842,16 @@ export namespace TableSchema {
845842
/**
846843
* The column to insert.
847844
*/
848-
readonly column: TInsertableColumn;
845+
readonly column: InsertableTreeNodeFromImplicitAllowedTypes<TColumn>;
849846
}
850847

851848
/**
852849
* {@link TableSchema.ITable.insertRows} parameters.
853850
* @internal
854851
*/
855-
export interface InsertRowsParameters<TInsertableRow> {
852+
export interface InsertRowsParameters<
853+
TRow extends ImplicitAllowedTypes = ImplicitAllowedTypes,
854+
> {
856855
/**
857856
* The index at which to insert the new rows.
858857
* @remarks If not provided, the rows will be appended to the end of the table.
@@ -862,14 +861,16 @@ export namespace TableSchema {
862861
/**
863862
* The rows to insert.
864863
*/
865-
readonly rows: TInsertableRow[];
864+
readonly rows: InsertableTreeNodeFromImplicitAllowedTypes<TRow>[];
866865
}
867866

868867
/**
869868
* {@link TableSchema.ITable.setCell} parameters.
870869
* @internal
871870
*/
872-
export interface SetCellParameters<TInsertableCell> {
871+
export interface SetCellParameters<
872+
TColumn extends ImplicitAllowedTypes = ImplicitAllowedTypes,
873+
> {
873874
/**
874875
* The key to uniquely identify a cell in a table.
875876
*/
@@ -878,17 +879,17 @@ export namespace TableSchema {
878879
/**
879880
* The cell to set.
880881
*/
881-
readonly cell: TInsertableCell;
882+
readonly cell: InsertableTreeNodeFromImplicitAllowedTypes<TColumn>;
882883
}
883884

884885
/**
885886
* A table.
886887
* @sealed @internal
887888
*/
888889
export interface ITable<
889-
TCell extends ImplicitAllowedTypes,
890-
TColumn extends ImplicitAllowedTypes,
891-
TRow extends ImplicitAllowedTypes,
890+
TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
891+
TColumn extends ImplicitAllowedTypes = ImplicitAllowedTypes,
892+
TRow extends ImplicitAllowedTypes = ImplicitAllowedTypes,
892893
> {
893894
/**
894895
* The table's columns.
@@ -922,25 +923,21 @@ export namespace TableSchema {
922923
* @throws Throws an error if the column is already in the tree, or if the specified index is out of range.
923924
*/
924925
insertColumn(
925-
params: InsertColumnParameters<InsertableTreeNodeFromImplicitAllowedTypes<TColumn>>,
926+
params: InsertColumnParameters<TColumn>,
926927
): TreeNodeFromImplicitAllowedTypes<TColumn>;
927928

928929
/**
929930
* Inserts 0 or more rows into the table.
930931
* @throws Throws an error if any of the rows are already in the tree, or if the specified index is out of range.
931932
*/
932-
insertRows(
933-
params: InsertRowsParameters<InsertableTreeNodeFromImplicitAllowedTypes<TRow>>,
934-
): TreeNodeFromImplicitAllowedTypes<TRow>[];
933+
insertRows(params: InsertRowsParameters<TRow>): TreeNodeFromImplicitAllowedTypes<TRow>[];
935934

936935
/**
937936
* Sets the cell at the specified location in the table.
938937
* @remarks To remove a cell, call {@link TableSchema.ITable.removeCell} instead.
939938
* @privateRemarks TODO: add overload that takes column/row nodes?
940939
*/
941-
setCell(
942-
params: SetCellParameters<InsertableTreeNodeFromImplicitAllowedTypes<TCell>>,
943-
): void;
940+
setCell(params: SetCellParameters<TCell>): void;
944941

945942
/**
946943
* Removes the specified column from the table.

0 commit comments

Comments
 (0)