Not getting a typescript error for insert

import { db } from "./db";
import {users} from "./schema";

// gives no error, but it should ??
const val = { name: 'a',incorrectFieldName: 2 };
await db.insert(users).values(val)

// gives error "Object literal may only specify known properties"
await db.insert(users).values({ name: 'a', incorrectFieldName: 2 })
import { db } from "./db";
import {users} from "./schema";

// gives no error, but it should ??
const val = { name: 'a',incorrectFieldName: 2 };
await db.insert(users).values(val)

// gives error "Object literal may only specify known properties"
await db.insert(users).values({ name: 'a', incorrectFieldName: 2 })
you can copy paste here https://drizzle.run/
1 Reply
Mario564
Mario5642w ago
@Нарбек val loosely resembles the shape for the table's insert, since TS has a loose type system. Drizzle will filter out any excess properties, but if you want an exact match, you can type val as val: typeof users.$inferInsert
Want results from more Discord servers?
Add your server