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]:strange bug #1089

Closed
sanghanihimanshu opened this issue Aug 22, 2023 · 7 comments · Fixed by #1102
Closed

[BUG]:strange bug #1089

sanghanihimanshu opened this issue Aug 22, 2023 · 7 comments · Fixed by #1102
Assignees
Labels
bug Something isn't working

Comments

@sanghanihimanshu
Copy link

What version of drizzle-orm are you using?

0.28.3

What version of drizzle-kit are you using?

No response

Describe the Bug

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

export const User = pgTable(
  "users",
  {
    id: uuid("id").primaryKey().defaultRandom(),
    username: varchar("username", { length: 255 }),
  }
);
[{
	"resource": "/E:/edgex/edgex-tools/edgex-api/src/Database/schma.ts",
	"owner": "typescript",
	"code": "2322",
	"severity": 8,
	"message": "Type 'PgVarcharBuilderInitial<\"username\", [string, ...string[]]>' is not assignable to type 'PgColumnBuilder<ColumnBuilderBaseConfig<ColumnDataType, string> & { data: any; }, object, object, ColumnBuilderExtraConfig>'.\n  The types of 'array(...).array(...)._' are incompatible between these types.\n    Type 'ColumnBuilderTypeConfig<{ name: \"username\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[][]; driverParam: string | (string | string[])[]; enumValues: [string, ...string[]]; }, { baseBuilder: PgColumnBuilder<{ name: \"username\"; ... 4 more ...; enumValues: [...]; }, object, object, ColumnBuilderExtraConfig>...' is not assignable to type 'ColumnBuilderTypeConfig<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[][]; driverParam: string | (string | unknown[])[]; enumValues: string[] | undefined; }, { baseBuilder: PgColumnBuilder<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[]; driverParam: string | unknown[]; en...'.\n      Type 'ColumnBuilderTypeConfig<{ name: \"username\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[][]; driverParam: string | (string | string[])[]; enumValues: [string, ...string[]]; }, { baseBuilder: PgColumnBuilder<{ name: \"username\"; ... 4 more ...; enumValues: [...]; }, object, object, ColumnBuilderExtraConfig>...' is not assignable to type '{ baseBuilder: PgColumnBuilder<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[]; driverParam: string | unknown[]; enumValues: string[] | undefined; }, object, object, ColumnBuilderExtraConfig>; }'.\n        Types of property 'baseBuilder' are incompatible.\n          Type 'PgColumnBuilder<{ name: \"username\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[]; driverParam: string | string[]; enumValues: [string, ...string[]]; }, object, object, ColumnBuilderExtraConfig>' is not assignable to type 'PgColumnBuilder<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[]; driverParam: string | unknown[]; enumValues: string[] | undefined; }, object, object, ColumnBuilderExtraConfig>'.\n            Type 'string' is not assignable to type '\"username\"'.",
	"source": "ts",
	"startLineNumber": 9,
	"startColumn": 5,
	"endLineNumber": 9,
	"endColumn": 13
}]
[{
	"resource": "/E:/edgex/edgex-tools/edgex-api/src/Database/schma.ts",
	"owner": "typescript",
	"code": "2322",
	"severity": 8,
	"message": "Type 'HasDefault<NotNull<PgUUIDBuilderInitial<\"id\">>>' is not assignable to type 'PgColumnBuilder<ColumnBuilderBaseConfig<ColumnDataType, string> & { data: any; }, object, object, ColumnBuilderExtraConfig>'.\n  The types of 'array(...).array(...)._' are incompatible between these types.\n    Type 'ColumnBuilderTypeConfig<{ name: \"id\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[][]; driverParam: string | (string | string[])[]; enumValues: undefined; }, { baseBuilder: PgColumnBuilder<{ name: \"id\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[]; driverParam: string | string[]; enumValues: u...' is not assignable to type 'ColumnBuilderTypeConfig<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[][]; driverParam: string | (string | unknown[])[]; enumValues: string[] | undefined; }, { baseBuilder: PgColumnBuilder<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[]; driverParam: string | unknown[]; en...'.\n      Type 'ColumnBuilderTypeConfig<{ name: \"id\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[][]; driverParam: string | (string | string[])[]; enumValues: undefined; }, { baseBuilder: PgColumnBuilder<{ name: \"id\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[]; driverParam: string | string[]; enumValues: u...' is not assignable to type '{ baseBuilder: PgColumnBuilder<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[]; driverParam: string | unknown[]; enumValues: string[] | undefined; }, object, object, ColumnBuilderExtraConfig>; }'.\n        Types of property 'baseBuilder' are incompatible.\n          Type 'PgColumnBuilder<{ name: \"id\"; dataType: \"array\"; columnType: \"PgArray\"; data: string[]; driverParam: string | string[]; enumValues: undefined; }, object, object, ColumnBuilderExtraConfig>' is not assignable to type 'PgColumnBuilder<{ name: string; dataType: \"array\"; columnType: \"PgArray\"; data: any[]; driverParam: string | unknown[]; enumValues: string[] | undefined; }, object, object, ColumnBuilderExtraConfig>'.\n            Type 'string' is not assignable to type '\"id\"'.",
	"source": "ts",
	"startLineNumber": 8,
	"startColumn": 5,
	"endLineNumber": 8,
	"endColumn": 7
}]

image

https://github.com/EDGEX3/edgex-api

Expected behavior

It doesn't accept schema

Environment & setup

Typescript
Node.js,
progress
https://github.com/EDGEX3/edgex-api

@sanghanihimanshu
Copy link
Author

sanghanihimanshu commented Aug 23, 2023

There is an problem in typescript.config.ts
It create important problems and if we use strict mode to compile type script then it need specific typing
This is the solution

export const your table name = pgTable(
  "users",
  <Record<string,PgColumnBuilder>><unknown>{
      //... define your schema 
  });

👨‍🔧

@Enalmada
Copy link

Enalmada commented Aug 23, 2023

That improves the situation but I still seem to have issues with relations

image

For reproduction:

import { relations, type InferInsertModel, type InferSelectModel } from 'drizzle-orm';
import { integer, pgEnum, pgTable, timestamp, varchar, type PgColumnBuilder } from 'drizzle-orm/pg-core';
import { nanoid } from 'nanoid';

export const UserTable = pgTable('user', <Record<string, PgColumnBuilder>>(<unknown>{
  id: varchar('id')
      .$type<string>()
      .$defaultFn(() => nanoid())
      .primaryKey(),
  firebaseId: varchar('firebase_id').unique(),
  name: varchar('name', { length: 255 }),
  email: varchar('email', { length: 320 }),
  image: varchar('image', { length: 2083 }),
}));

export type User = InferSelectModel<typeof UserTable>;
export type UserInput = InferInsertModel<typeof UserTable>;

export const usersRelations = relations(UserTable, ({ many }) => ({
  task: many(TaskTable),
}));

export const TaskStatus = pgEnum('status', ['ACTIVE', 'COMPLETED']);

export const TaskTable = pgTable('task', <Record<string, PgColumnBuilder>>(<unknown>{
  id: varchar('id')
      .$type<string>()
      .$defaultFn(() => nanoid())
      .primaryKey(),
  title: varchar('name', { length: 256 }).notNull(),
  description: varchar('description', { length: 1024 }),
  status: TaskStatus('status'),
  dueDate: timestamp('due_date'),
  userId: varchar('user_id').references(() => UserTable.id, { onDelete: 'cascade' }),
}));

export type Task = InferSelectModel<typeof TaskTable>;
export type TaskInput = InferInsertModel<typeof TaskTable>;

export const taskRelations = relations(TaskTable, ({ one }) => ({
  user: one(UserTable, {
    fields: [TaskTable.id],
    references: [UserTable.id],
  }),
}));

I also don't seem to be getting the right return type from queries (but I am new to drizzle and may be misunderstanding something)
image

@sanghanihimanshu
Copy link
Author

sanghanihimanshu commented Aug 23, 2023

You can try turning off type script compilation

{
"Strict": false,
}

@AndriiSherman
Copy link
Member

I would suggest downgrading to 0.28.2 for now vs. setting strict: false
0.28.4 with all fixes should be in latest soon

dankochetov added a commit that referenced this issue Aug 23, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Public Roadmap Aug 23, 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
@alexiuscrow
Copy link

0.28.4 with all fixes should be in latest soon

Hi @AndriiSherman. I'm using 0.29.4, but I've experienced the same issue.
Could it be a regression?

Знімок екрана 2024-02-28 о 23 17 41

@stepanorda
Copy link

@dankochetov looks like the same type of error in 0.32.1, if I remove .primaryKey() everything is fine:
image

@berkerdemirer
Copy link

Same issue in 0.33.0

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.

7 participants