Typed selected rows
Define a reusable TypeScript type for rows returned from a table.
Drizzle ORM · Type Alias
InferSelectModel derives a TypeScript select-row model from a Drizzle table schema. Pass the table type with typeof to avoid manually duplicating the row shape.
InferSelectModel derives the TypeScript shape of rows selected from a Drizzle table schema. Pass the table type as its generic argument; the resulting alias can describe values returned by select queries without manually duplicating the schema.
InferSelectModel<typeof table>| Name | Type | Description |
|---|---|---|
TTable | typeof users (a table type) | A Drizzle table type whose selected-row shape should be inferred. |
A TypeScript model type representing selected rows for the supplied Drizzle table.
typeof, for example InferSelectModel<typeof users>.drizzle-orm package.$inferSelect property provides an alternative syntax for the same selected-row inference.import { integer, text, sqliteTable } from "drizzle-orm/sqlite-core";
import { type InferSelectModel } from "drizzle-orm";
const users = sqliteTable("users", {
id: integer().primaryKey({ autoIncrement: true }),
name: text().notNull(),
});
type User = InferSelectModel<typeof users>;
const user: User = { id: 1, name: "Ada" };Infer a TypeScript type representing rows selected from the declared table.
Define a reusable TypeScript type for rows returned from a table.
Expose database row types from a repository or service layer without repeating column definitions.
Choose explicitly between selected-row and insert-value models in application types.
InferSelectModel is a Drizzle type helper that derives a select-row TypeScript model from a table schema. Use it as InferSelectModel<typeof users> after importing it from drizzle-orm.
Follow-up: How can the same model be inferred without the helper? Use the table’s $inferSelect property, such as typeof users.$inferSelect.
Its generic argument is the table type, commonly written as typeof users. The inferred result follows the columns and constraints declared in that table schema.
Follow-up: What helper represents values intended for insertion? InferInsertModel<typeof users> derives the insert model instead.
$inferSelect?It is an alternative to the table property form: InferSelectModel<typeof users> is shown alongside typeof users.$inferSelect. Both are documented ways to infer a selected-row model.
Follow-up: Why prefer the explicit helper in some codebases? It makes the selected-versus-insert distinction visible at the type name, unlike the older generic InferModel.
InferInsertModel$inferSelect$inferInsertInferModel