Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: PgTransaction Type with ExtractTablesWithRelations errors in 0.28.0 but not 0.27.2 #983

Closed
Cherry opened this issue Aug 6, 2023 · 0 comments · Fixed by #994
Closed
Assignees
Labels
bug Something isn't working

Comments

@Cherry
Copy link
Contributor

Cherry commented Aug 6, 2023

What version of drizzle-orm are you using?

0.28.0

What version of drizzle-kit are you using?

0.19.12

Describe the Bug

When using .array() within a postgres schema, the PgTransaction type with ExtractTablesWithRelations now throws an error when it didn't previously in 0.27.x.

import {
	pgTable, uuid, varchar,
} from 'drizzle-orm/pg-core';

import type {PgTransaction} from 'drizzle-orm/pg-core';
import type {NeonQueryResultHKT} from 'drizzle-orm/neon-serverless';
import type {ExtractTablesWithRelations} from 'drizzle-orm';

export const table1 = pgTable('test', {
	id: uuid('id').defaultRandom().primaryKey(),
	username: varchar('username', {
		length: 64,
	}).notNull(),
	array_field: varchar('array_field', {
		length: 64,
	}).array(),
});

const schema = {
	table1,
};

type ExtractedRelations = ExtractTablesWithRelations<typeof schema>;

// errors as below. Works perfectly if you comment out the above `array_field` field
type DBTransaction = PgTransaction<NeonQueryResultHKT, typeof schema, ExtractedRelations>;

Errors with:

Type 'ExtractTablesWithRelations<{ table1: PgTableWithColumns<{ name: "test"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "test"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; usern...' does not satisfy the constraint 'TablesRelationalConfig'.
  Property 'table1' is incompatible with index signature.
    Type '{ tsName: "table1"; dbName: "test"; columns: { id: PgColumn<{ name: "id"; tableName: "test"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; username: PgColumn<...>; array_field: PgColumn<...>; }; rela...' is not assignable to type 'TableRelationalConfig'.
      Types of property 'columns' are incompatible.
        Type '{ id: PgColumn<{ name: "id"; tableName: "test"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; username: PgColumn<...>; array_field: PgColumn<...>; }' is not assignable to type 'Record<string, AnyColumn>'.
          Property 'array_field' is incompatible with index signature.
            Type 'PgColumn<{ name: "array_field"; tableName: "test"; dataType: "array"; columnType: "PgArray"; data: string[]; driverParam: string | string[]; notNull: false; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: Column<...>; }, {}, {}>' is not assignable to type 'AnyColumn'.
              Types of property '_' are incompatible.
                Type 'ColumnTypeConfig<{ name: "array_field"; tableName: "test"; dataType: "array"; columnType: "PgArray"; data: string[]; driverParam: string | string[]; notNull: false; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: Column<...>; }, { ...; }>' is not assignable to type 'ColumnTypeConfig<Required<{ data: unknown; name: string; dataType: ColumnDataType; columnType: string; driverParam: unknown; enumValues: string[] | undefined; tableName: string; notNull: boolean; hasDefault: boolean; }>, object>'.
                  Type 'ColumnTypeConfig<{ name: "array_field"; tableName: "test"; dataType: "array"; columnType: "PgArray"; data: string[]; driverParam: string | string[]; notNull: false; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: Column<...>; }, { ...; }>' is not assignable to type '{ brand: "Column"; tableName: string; name: string; dataType: ColumnDataType; columnType: string; data: unknown; driverParam: unknown; notNull: boolean; hasDefault: boolean; enumValues: string[] | undefined; baseColumn: never; }'.
                    Types of property 'baseColumn' are incompatible.
                      Type 'Column<{ name: "array_field"; tableName: "test"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: false; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, object, object>' is not assignable to type 'never'.

Expected behavior

If I comment out the array_field everything works as expected, as well as if I downgrade to 0.27.2. The intent here is to pass around a tx: DBTransaction between functions for code separation, and worked well in 0.27.2.

Environment & setup

Node.js 18.17.0

@Cherry Cherry added the bug Something isn't working label Aug 6, 2023
@dankochetov dankochetov self-assigned this Aug 6, 2023
@dankochetov dankochetov moved this to Todo in Public Roadmap Aug 6, 2023
dankochetov added a commit that referenced this issue Aug 7, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Public Roadmap Aug 7, 2023
minjie0501 pushed a commit to minjie0501/drizzle-orm that referenced this issue Aug 26, 2023
prometixX pushed a commit to prometixX/drizzle-orm-mssql that referenced this issue Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants