-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Environment
Knex version: 0.21.15
Database + version: postgresql 13
OS: ubuntu
Bug
-
Explain what kind of behaviour you are getting and how you think it should do
onConflictandmergeshould interact nicely withKnex.CompositeTableType -
Error message
for.onConflict:Argument of type 'string' is not assignable to parameter of type 'readonly ("base" | "insert" | "update")[]
for .merge: Argument of type '{ insert_only_field: string; }' is not assignable to parameter of type 'Readonly<Partial<MaybeRawRecord<CompositeTableType<DBUser, Pick<DBUser, "name" | "insert_only_field">, Pick<DBUser, "name">>>>>'. Object literal may only specify known properties, and 'insert_only_field' does not exist in type 'Readonly<Partial<MaybeRawRecord<CompositeTableType<DBUser, Pick<DBUser, "name" | "insert_only_field">, Pick<DBUser, "name">>>>>'
- Reduced test code, for example in https://npm.runkit.com/knex or if it needs real
database connection to MySQL or PostgreSQL, then single file example which initializes
needed data and demonstrates the problem.
import Knex from "knex";
import knex from './client';
declare module "knex/types/tables" {
interface DBUser {
id: string;
insert_only_field: string;
name: string;
}
interface Tables {
users: Knex.CompositeTableType<DBUser,
// insert
Pick<DBUser, 'name' | 'insert_only_field'>,
// update
Pick<DBUser, 'name'>
>;
}
}
await knex('users')
.insert({ name: "Bob", insert_only_field: "1" })
.onConflict("insert_only_field") // type error here
.merge({
name: "Bob",
insert_only_field: knex.raw("EXCLUDED.insert_only_field"), // raw also fails with different error
})
;