Check out this code snippet:
interface DummyTableRow {
id: number;
name: string;
}
interface RowChange<Row extends object> {
newRow: Row | null;
oldRow: Row | null;
}
interface RowChangeBag {
Dummy: RowChangeList<DummyTableRow>;
}
type RowChangeList<Row extends object> = Array<RowChange<Row>>;
function add<
Row extends object,
T extends keyof RowChangeBag,
// receiving an error on the following line: Type 'DummyTableRow' is not assignable to type 'Row'.
L extends RowChangeList<Row> = RowChangeBag[T]
>(
bag: RowChangeBag,
tableName: T,
newRow: Row | null,
oldRow: Row | null,
) {
bag[tableName].push({ newRow, oldRow });
}
Any idea why it's showing an error? Why can't it assign DummyTableRow
to Row
?
Do you think this might be a TypeScript issue? (I'm using version 2.6.2 for reference)