Type insert-service inputs
Define a reusable type for objects passed to an insert function.
Drizzle ORM · Type Alias
InferInsertModel derives the TypeScript shape for inserting rows from a Drizzle table schema. It is used as InferInsertModel<typeof users> and has a table-property equivalent, $inferInsert.
InferInsertModel receives a Drizzle table type and produces the TypeScript shape accepted when inserting into that table. In the documented example, the inferred insert type permits omitting an auto-incremented primary key while retaining the required name field.
InferInsertModel<typeof table>| Name | Type | Description |
|---|---|---|
TTable | typeof users | The Drizzle table type whose insert-row shape should be inferred. |
The insert model type inferred from the supplied Drizzle table schema.
drizzle-orm package.typeof the table to create a named insert-row type.$inferInsert as a concise alternative to the standalone helper.$inferInsert property is an alternative to the InferInsertModel helper; choose either form consistently.import { integer, text, sqliteTable } from 'drizzle-orm/sqlite-core';
import { type InferInsertModel } from 'drizzle-orm';
const users = sqliteTable('users', {
id: integer().primaryKey({ autoIncrement: true }),
name: text().notNull(),
});
type NewUser = InferInsertModel<typeof users>;
const newUser: NewUser = { name: 'Alef' };Infer an insert model from the table schema, then use it to type a new row; the auto-incremented id is omitted.
Define a reusable type for objects passed to an insert function.
Avoid manually duplicating fields and optionality from a table schema.
Use the same inference pattern across Drizzle-supported table schemas.
InferInsertModel is a Drizzle type helper that derives an insert-row type from a table schema. It is used as InferInsertModel<typeof users> and is shown alongside the table's $inferInsert type.
Follow-up: How can the same type be obtained without the helper? Use typeof users.$inferInsert.
Pass the table object as the helper's generic argument: InferInsertModel<typeof users>. The resulting alias can type an object passed to an insert operation.
Follow-up: What must the generic argument represent? It must be the Drizzle table value's type, obtained with typeof.
It describes data for inserting rows, rather than the selected-row model. In the documented schema, the generated id can be omitted from the insert object while name remains available as a field.
Follow-up: What alternative is documented for the same purpose? The table-level .$inferInsert property.
InferSelectModel$inferInsert$inferSelect