Subquery type error when using generics

I have the following simple query being generated by my function f:
const f = () => queryBuilder
            .deleteFrom(`table as t1`)
            .whereExists(qb => qb.selectFrom(`table as t2`)
                .whereRef('t1.col1', '>=', 't2.col1')
            )

and it works fine. If I add a generic for reusing the same function with different tables (all sharing the common col1 column) it works fine, until I get to the sub query whereRef (even if I constraint the generic to a single value, which is the same
table
as before):
const f = <T extends 'table'>(table: T) => queryBuilder
            .deleteFrom(`${table} as t1`)
            .whereExists(qb => qb.selectFrom(`${table} as t2`)
                /* here it can't find the refs to t1.col1 or t2.col1 */.whereRef('t1.col1', '>=', 't2.col1')
            )
Was this page helpful?