drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.03k stars 556 forks source link

[BUG]: Nullable columns do not exist in insert(table).values() #2694

Open PhilipAngelinNE opened 1 month ago

PhilipAngelinNE commented 1 month ago

What version of drizzle-orm are you using?

0.32.1

What version of drizzle-kit are you using?

0.23.0

Describe the Bug

const files = pgTable("files", {
  id: uuid("id").primaryKey().defaultRandom(),
  externalId: char("externalId", { length: 30 }).notNull(),
  password: char("password", { length: 30 }),
  size: bigint("size", { mode: "number" }).notNull(), // In bytes
  expires: bigint("expires", { mode: "number" }).notNull(), // UNIX timestamp
});
this.db.insert(files).values({ externalId, size, expires, password })

Here, TS complains that password does not exist in the values object. If I add .notNull() to the password column it works.

Expected behavior

In this case, password should exist in .values().

Environment & setup

OS: WSL Ubuntu. TypeScript version: 5.4.5. Node version: 20. Using Nx mono repo with a NestJS app (where the example is used).

PhilipAngelinNE commented 1 month ago

I found in https://github.com/drizzle-team/drizzle-orm/issues/2654#issuecomment-2247698796 that this only seems to happen with tsconfig strict mode set to false. Nx does not set it to true, so I turned them on myself and that fixed the issue.

However I have a friend who tried doing the same, and it does still not work for him, so I'll leave this issue open.

micaww commented 1 month ago

seems to be an issue only 0.32+. i downgraded to 0.31.2 and the nullable properties are correctly in the insert type

lmcneel commented 1 month ago

seems to be an issue only 0.32+. I downgraded to 0.31.2, and the nullable properties are correctly in the insert type

Unfortunately, we ran into an issue with drizzle-kit which requires the latest version. I, too, initially downgraded until we needed to run migrations.

krunalshahcodes commented 3 weeks ago

I have spent like an hour trying to fix this issue. I was using v0.33 i tried downgrading to v0.32 but still didn't work. Adding the strict:true to tsconfig.json solved the issue for me.

Karo8870 commented 3 weeks ago

I'm not sure if this is a framework problem, but for me setting "strictNullChecks" to true instead of "strict" did the trick. I'm using NestJS with DrizzleORM v0.33.0