RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
690 stars 62 forks source link

Array data types does not return the correct TS type #160

Open caalberts opened 4 weeks ago

caalberts commented 4 weeks ago

Given the following schema:

CREATE table bookshelf(
  id bigserial NOT NULL,
  book_ids bigint[] NOT NULL);

The generated type is as follows:

export interface Bookshelf {
  id: Generated<Int8>
  book_ids: Int8[]
}

This type does not accept an array of numbers. The following code doesn't compile with Type number[] is not assignable to type Int8[]

await db
        .insertInto('bookshelf')
        .values({
          book_ids: [12, 23]
        })
        .execute()

However, if the array type is changed to the following as suggested in https://github.com/kysely-org/kysely/issues/957#issuecomment-2071085703, the same code compiles:

type Int8Array = ColumnType<
  SelectType<Int8>[],
  InsertType<Int8>[],
  UpdateType<Int8>[]
>;

export interface Bookshelf {
  id: Generated<Int8>
  book_ids: Int8Array
}

Upvote & Fund

Fund with Polar