Using generics with Table type

hey there, I'm trying to create a generic function, something like this:
function insertWithLogger<DataType>(data: DataType[], table: SomeTableType<Data>) {
logger.info("Inserting data, wow!")
db.insert(table).values(data)
logger.info("inserted data, amazing!")
}
function insertWithLogger<DataType>(data: DataType[], table: SomeTableType<Data>) {
logger.info("Inserting data, wow!")
db.insert(table).values(data)
logger.info("inserted data, amazing!")
}
Somebody know how to type SomeTableType<DataType> properly?
1 Reply
BaNuni
BaNuniOP5mo ago
Found my answer! ended up doing:
function insertWithLogger<TableType extends AnyPgTable, DataType extends InferInsertModel<TableType>>(data: DataType[], table: TableType)
function insertWithLogger<TableType extends AnyPgTable, DataType extends InferInsertModel<TableType>>(data: DataType[], table: TableType)
(can be marked as an answer, I'm not sure how to...)
Want results from more Discord servers?
Add your server