0Pricing
TypeScript Academy · Lesson

Inferring Query Result Shapes

Let the query builder infer the returned row type.

The Result Type Follows the Selection

A great query builder does not just validate input; it infers the exact shape of each result row from the columns you selected. Select fewer columns and the result type narrows.

Full Row Select

Calling select() with no projection returns the entire row type.

const rows = await db.select().from(users);
// rows: { id: number; name: string; age: number | null; isAdmin: boolean }[]

All lessons in this course

  1. Schema-to-Type Mapping
  2. Type-Safe Query Construction
  3. Inferring Query Result Shapes
  4. Relations and Joins with Types
← Back to TypeScript Academy