-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
bugSomething isn't workingSomething isn't working
Description
pluck().map() result is typed incorrectly:
const attributedIds = await db.user.pluck("id").map(id => ({ id, age: 18 }))
console.log(attributedIds)
// ERROR: attributedIds typed as { id: number; age: number; }
// CORRECT: prints [{ id: 1, age: 18 }, { id: 2, age: 18 }]Full reproduction
// orchid-orm@1.62.3
import { createBaseTable, testTransaction } from "orchid-orm"
import { orchidORM } from "orchid-orm/postgres-js"
export const BaseTable = createBaseTable({ snakeCase: true })
export class UserTable extends BaseTable {
override readonly table = "user"
override columns = this.setColumns(t => ({
id: t.serial().primaryKey(),
name: t.varchar(),
}))
}
const db = orchidORM({ log: true }, {
user: UserTable,
})
async function main() {
await testTransaction.start(db)
await db.$query`create table "user" (id serial primary key, name varchar not null)`
await db.user.insertMany([{ name: "Alice" }, { name: "Bob" }])
const ids = await db.user.pluck("id") // typed as number[]
console.log([...ids])
// CORRECT: ids typed as number[]
// CORRECT: prints 1, 2
const attributedIds = await db.user.pluck("id").map(id => ({ id, age: 18 }))
console.log(attributedIds)
// ERROR: attributedIds typed as { id: number; age: number; }
// CORRECT: prints [{ id: 1, age: 18 }, { id: 2, age: 18 }]
await testTransaction.close(db)
}
main()Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working