client-ts icon indicating copy to clipboard operation
client-ts copied to clipboard

Type error on transaction delete with const table name

Open tsg opened this issue 1 year ago • 0 comments

Describe the bug

The transaction API requires the table name as const, but in a situation like this you get an error:

const records = await xata.db.test.getAll();
const toDelete = records.map(rec => {
    return {
        delete: {
            table: 'test',
            id: rec.id
        }
    }
})
const page = await xata.transactions.run(toDelete);
console.log(page);

The workaround is to do 'test' as const like this:

const records = await xata.db.test.getAll();
const toDelete = records.map(rec => {
    return {
        delete: {
            table: 'test' as const,
            id: rec.id
        }
    }
})
const page = await xata.transactions.run(toDelete);
console.log(page);

To avoid this issue, @SferaDev suggested that we could accept string & {} so that auto-complete still works.

tsg avatar Mar 11 '24 16:03 tsg