Type inference breaking in drizzle-orm 0.32.0 ?

I am trying to update a column called 'isEmailVerified'but TS keeps telling me that 'isEmailVerified' doesn't exist in the schema. Everything used to work fine in the previous version. const updatedUserId: { updatedId: number }[] = await this.db .update(users) .set({ isEmailVerified: true }) .where(eq(users.email, email)) .returning({ updatedId: users.id }); My schema is the following : export const users = pgTable('users', { id: serial('id').primaryKey(), email: varchar('email').unique().notNull(), firstName: varchar('first_name').notNull(), lastName: varchar('last_name').notNull(), password: varchar('password').notNull(), phone: varchar('phone'), roleId: integer('role_id').references(() => userRoles.id), isEmailVerified: boolean('is_email_verified').default(false), createdAt: timestamp('created_at').defaultNow(), }); For some reason, it only sees columns that have 'notNull' constraint.
14 Replies
rphlmr ⚡
rphlmr ⚡5mo ago
👋 Can you share you ts config?
helloworld1_1
helloworld1_1OP5mo ago
here's my tsconfig.json { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", "types": ["node"], "emitDecoratorMetadata": true, "target": "es2021" }, "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], "include": ["src/**/*.ts"] } and here's my tsconfig.app.json { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", "types": ["node"], "emitDecoratorMetadata": true, "target": "es2021" }, "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], "include": ["src/**/*.ts"] }
rphlmr ⚡
rphlmr ⚡5mo ago
Thx, you are extending from a tsconfig.json, can you share it. If it is not possible, I am looking to see if you have strict mode set to true because Drizzle needs that to properly infer types.
helloworld1_1
helloworld1_1OP5mo ago
No I am not setting strict mode to true but it used to work fine without strict mode { "extends": "../../tsconfig.base.json", "files": [], "include": [], "references": [ { "path": "./tsconfig.app.json" }, { "path": "./tsconfig.spec.json" } ], "compilerOptions": { "esModuleInterop": true } } { "compileOnSave": false, "compilerOptions": { "rootDir": ".", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "importHelpers": true, "target": "es2015", "module": "esnext", "lib": ["es2020", "dom"], "skipLibCheck": true, "skipDefaultLibCheck": true, "baseUrl": ".", }, "exclude": ["node_modules", "tmp"] }
rphlmr ⚡
rphlmr ⚡5mo ago
Yes, I don't know when it started but strict mode should fix your issue. Drizzle has a complex typing system that relies on it. It is enabled by default on many project starters. You can check this blog post as a reference https://www.totaltypescript.com/tsconfig-cheat-sheet
Total TypeScript
The TSConfig Cheat Sheet
Learn the essential TypeScript configuration options and create a concise tsconfig.json file for your projects with this helpful cheatsheet.
helloworld1_1
helloworld1_1OP5mo ago
Well, I guess setting 'strict' to true was what's missing. Thanks. Raphaël.
kangkang
kangkang5mo ago
But I think this is a breaking update which will cause most of the code error why is it not mandatory in version 0.31 I think the type of optional field should be field?: xxx instead of field: xxx | undefined😵‍💫
rphlmr ⚡
rphlmr ⚡5mo ago
I really don’t know if it is intentional or not because I use ts strict mode in all my projects 😬 I will report that to the team Where did you see undefined as type?
kangkang
kangkang5mo ago
If strictNullChecks in tsconfig.json is set to true, then the type of the optional field is field: xxx | undefined
rphlmr ⚡
rphlmr ⚡5mo ago
Isn’t because of unsafe index check in tsconfig or something like that? This extra tsconfig security makes all items of an array T | undefined
kangkang
kangkang5mo ago
If it's convenient for you, I'll chat with you privately
rphlmr ⚡
rphlmr ⚡5mo ago
Sure 👍
kangkang
kangkang5mo ago
I've messaged you privately. Please check.😄
rphlmr ⚡
rphlmr ⚡5mo ago
Yes lol just taking my morning coffee and I come back :p
Want results from more Discord servers?
Add your server