Open
Description
Report hasn't been filed before.
- I have verified that the bug I'm about to report hasn't been filed before.
What version of drizzle-orm
are you using?
0.41.0
What version of drizzle-kit
are you using?
0.30.6
Other packages
No response
Describe the Bug
With strictNullChecks: false
, drizzle produces the wrong type for InferInsertModel
:
import { integer, jsonb, pgTable, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
import { type InferInsertModel } from 'drizzle-orm'
export const test = pgTable('test', {
id: uuid('id').defaultRandom().primaryKey(),
foo: text('foo').notNull(),
bar: integer('bar').notNull(),
baz: varchar('baz', { length: 255 }),
json: jsonb('json').$type<{foo: string}>(),
date: timestamp('date').defaultNow().notNull(),
});
export type testSchema = InferInsertModel<typeof test>;
const example: testSchema = {
foo: 'hello',
bar: 123,
baz: 'world',
json: {foo: 'bar'},
date: new Date(),
}
tsconfig.json:
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"noEmit": true,
"target": "ESNext",
"module": "ESNext",
"lib": ["ESNext"],
"types": [],
"allowJs": true,
"strict": true,
"alwaysStrict": true,
"moduleResolution": "bundler",
"esModuleInterop": true,
"resolveJsonModule": true,
"strictNullChecks": false,
"skipLibCheck": true
}
}
With this, if you run npx tsc --noEmit
, you will observe errors like the following:
src/example.ts:18:2 - error TS2353: Object literal may only specify known properties, and 'baz' does not exist in type '{ foo: string; bar: number; }'.
18 baz: 'world',
~~~
Found 1 error in src/example.ts:18
This is because the type is missing any nullable properties:
If you edit the tsconfig.json
and enable strictNullChecks: true
, the error disappears.