RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
773 stars 69 forks source link

Type mismatch between kysely and codegen #140

Open christiannnc opened 6 months ago

christiannnc commented 6 months ago

I'm trying to insert a row into my Postgres database with Kysely, and it appears that the types provided by kysely-codegen are making it impossible. When running the following code, I get a Typescript error that says: Type 'ColumnType<number, number | undefined, number>' is not assignable to type 'ValueExpression<DB, DB_TABLE.Address, number>'.

My code:

db.insertInto('address').values(
    {
      ...values
      userId: user.id // error here
    }
  )

And here are my generated types for the address table:

export interface Address {
  city: string;
  country: string;
  id: Generated<number>;
  secondary: string;
  state: string;
  street: string;
  userId: number;
  zipcode: string;
}

Am I missing something here? I feel like I should be able to take the id property from a user and assign userId to that value, but Typescript disagrees.

Upvote & Fund

Fund with Polar

christiannnc commented 6 months ago

I just bumped my version to 0.14.0 and it looks like I get the same issue complaining about the generic Generated type. I was able to resolve it by doing 'as unknown as number', but I thought I'd create an issue in case this isn't expected behavior.

On Sun, Mar 17, 2024 at 11:57 PM Robin Blomberg @.***> wrote:

What version of kysely-codegen are you using? I released 0.14.0 yesterday which updated all dependencies.

— Reply to this email directly, view it on GitHub https://github.com/RobinBlomberg/kysely-codegen/issues/140#issuecomment-2003054325, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANTINPU6BSM2UGHPFQFNMZLYY2F6NAVCNFSM6AAAAABE2SNHIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBTGA2TIMZSGU . You are receiving this because you authored the thread.Message ID: @.***>

RobinBlomberg commented 6 months ago

I think this is a duplicate of #90. Can you check that issue and tell me if it solves your problem?