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]:drizzle typescript doesn't see boolean column #2900

Closed
Kaidstor opened this issue Sep 3, 2024 · 16 comments
Closed

[BUG]:drizzle typescript doesn't see boolean column #2900

Kaidstor opened this issue Sep 3, 2024 · 16 comments
Labels
bug Something isn't working priority Will be worked on next

Comments

@Kaidstor
Copy link

Kaidstor commented Sep 3, 2024

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

0.24.2

Describe the Bug

i have entity

export const db_ranges = pgTable('ranges', {
  id: serial('id').primaryKey(),
  fromIp: varchar('fromIp', { length: 20 }).notNull(),
  toIp: varchar('toIp', { length: 20 }).notNull(),
  createdAt: timestamp('createdAt').notNull(),
  active: boolean('active').notNull().default(true),
});

but when try to update it

 await db
    .update(db_ranges)
    .set({ active: false })
     where(eq(db_ranges.id, id));

see the error:
Object literal may only specify known properties, and 'active' does not exist in type '{ createdAt?: SQL | Date; country_code?: string | SQL; fromIp?: string | SQL; toIp?: string | SQL; }'.ts(2353)

Expected behavior

expect that I can to change boolean value and it contains in the ranges

Environment & setup

No response

@Kaidstor Kaidstor added the bug Something isn't working label Sep 3, 2024
@cayasso
Copy link

cayasso commented Sep 10, 2024

Getting this exact same problem, its started since drizzle-orm@0.32.0

@tamagokun
Copy link

tamagokun commented Sep 16, 2024

Same thing here, seems like the typescript types are wonky all of a sudden. Same error, different schema:

// schema.ts
export const event = sqliteTable(
  "Event",
  {
    id: text("id").primaryKey(),
    projectId: integer("projectId")
      .notNull()
      .references(() => project.id),
    type: text("type", { enum: ["EXCEPTION", "MESSAGE"] }).notNull(),
    message: text("message"),
    stack: text("stack", { mode: "json" }),
    meta: text("meta", { mode: "json" }),
    count: integer("count"),
    createdAt: text("createdAt").default(sql`(CURRENT_TIMESTAMP)`),
    lastEventAt: text("lastEventAt").default(sql`(CURRENT_TIMESTAMP)`),
    resolvedAt: text("resolvedAt"),
  },
  (table) => {
    return {
      projectIdx: index("projectIdx").on(table.projectId),
    };
  }
);
import { db, schema } from "../../../../../db";
import { and, eq } from "drizzle-orm";

await db
    .update(schema.event)
    .set({ resolvedAt: new Date().toISOString() })
    .where(
      and(
        eq(schema.event.id, String(eventId)),
        eq(schema.event.projectId, Number(projectId))
      )
    );
Object literal may only specify known properties, and 'resolvedAt' does not exist in type '{ projectId?: number | SQL<unknown>; id?: string | SQL<unknown>; type?: SQL<unknown> | "EXCEPTION" | "MESSAGE"; }'.ts(2353)

in a different file, typescript errors over the count column, and in another file, it errors over the id column. Doesn't seem to matter what column or column type, just any column when trying to make an update using set, or an insert using values

@jakeleventhal
Copy link

I can confirm this issue arises started in 0.32.0

@rphlmr
Copy link

rphlmr commented Oct 9, 2024

Hello 👋

Can you check if you have "strict": true in your tsconfig?

https://github.com/rphlmr/drizzle-on-indexeddb/blob/main/tsconfig.json

Here an the same schema with a tsconfig using strict mode: https://drizzle.run/x4vxq6rmgt0s0n5693poz5az

@tamagokun
Copy link

yes, using strict mode

@rphlmr
Copy link

rphlmr commented Oct 9, 2024

yes, using strict mode

@tamagokun I can't reproduce on https://drizzle.run/h64z5eeqpx5pki1my1xka3n5

Can you share your tsconfig? (here or on discord https://discord.com/channels/1043890932593987624/1293551158094467112)

@rphlmr
Copy link

rphlmr commented Oct 9, 2024

The Drizzle team suggests not using TypeScript versions higher than 5.4.5.

They are working on a fix to support newer versions.

@tamagokun
Copy link

Ah, that'll do it. Confirmed that rolling back to typescript 5.4.0 gets rid of the errors.

Posting my tsconfig anyways. afaik based off the auto-generated next.js tsconfig, but added a few things:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "incremental": true,
    "module": "esnext",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "jsxImportSource": "nativewind",
    "plugins": [
      {
        "name": "next"
      }
    ]
  },
  "include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

Also including package versions since mine may differ from the original issue's:

{
  "typescript": "5.4.5",
  "@libsql/client": "^0.6.2",
  "drizzle-orm": "^0.31.2"
}

@AndriiSherman
Copy link
Member

We have it as a priority, and if it doesn't require any major rewrites of types for new TypeScript versions, we will try to release it tomorrow

@AndriiSherman
Copy link
Member

Could someone check this tag drizzle-orm@upgrade_ts?
It should be compatible with newer TS versions

@AndriiSherman
Copy link
Member

If yes, will include in the next release

@jakeleventhal
Copy link

Hey @AndriiSherman, confirming this is still broken. More context on env: https://discord.com/channels/1043890932593987624/1293551158094467112

@jakeleventhal
Copy link

jakeleventhal commented Oct 16, 2024

Can confirm this is not in the latest release (0.35.1)

@L-Mario564 L-Mario564 added the priority Will be worked on next label Oct 24, 2024
@jakeleventhal
Copy link

@Kaidstor how can you "close" this if it is not resolved?

@Kaidstor
Copy link
Author

Kaidstor commented Oct 30, 2024

image

@jakeleventhal

on 0.36.0 drizzle-orm it works and ts 5.4+

@Kaidstor
Copy link
Author

i get another bug, and create new issue #3269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority Will be worked on next
Projects
None yet
Development

No branches or pull requests

7 participants