From 6dafa1664fc79a2367a1508ef723cf1b1af947fe Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Jan 2026 20:37:11 +0000 Subject: [PATCH 1/3] feat(db): Export ExtractContext type for extracting query result types This allows users to extract the result type from a Query instance: ```typescript import { Query, ExtractContext, GetResult } from '@tanstack/db' const myQuery = new Query() .from({ users }) .select(({ users }) => ({ name: users.name })) type MyQueryResult = GetResult> ``` Fixes a gap in the public API where ExtractContext was defined but not re-exported from the main query module. --- packages/db/src/query/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/db/src/query/index.ts b/packages/db/src/query/index.ts index e798b283a..c664117a8 100644 --- a/packages/db/src/query/index.ts +++ b/packages/db/src/query/index.ts @@ -10,6 +10,7 @@ export { type Source, type GetResult, type InferResultType, + type ExtractContext, } from './builder/index.js' // Expression functions exports From ad77b1682cbdfaba75f068b259d8162dc4ec8bce Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Jan 2026 20:51:29 +0000 Subject: [PATCH 2/3] chore: Add changeset for ExtractContext export --- .changeset/export-extract-context.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .changeset/export-extract-context.md diff --git a/.changeset/export-extract-context.md b/.changeset/export-extract-context.md new file mode 100644 index 000000000..674e295ff --- /dev/null +++ b/.changeset/export-extract-context.md @@ -0,0 +1,16 @@ +--- +'@tanstack/db': patch +--- + +Export `ExtractContext` type to enable extracting query result types from Query instances. + +```typescript +import { Query, ExtractContext, GetResult } from '@tanstack/db' + +const myQuery = new Query() + .from({ users }) + .select(({ users }) => ({ name: users.name })) + +// Extract the result type: +type MyQueryResult = GetResult> +``` From 7246fd60132962c817b8032a37aaf1f28542848f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 7 Jan 2026 14:22:20 +0000 Subject: [PATCH 3/3] feat(db): Add QueryResult helper type for extracting query result types Adds a simpler API similar to Zod's z.infer: ```typescript import { Query, QueryResult } from '@tanstack/db' const myQuery = new Query() .from({ users }) .select(({ users }) => ({ name: users.name })) type MyQueryResult = QueryResult ``` This is more ergonomic than the two-step approach: `GetResult>` --- .changeset/export-extract-context.md | 10 ++++++---- packages/db/src/query/builder/index.ts | 4 ++++ packages/db/src/query/index.ts | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.changeset/export-extract-context.md b/.changeset/export-extract-context.md index 674e295ff..7557afe1d 100644 --- a/.changeset/export-extract-context.md +++ b/.changeset/export-extract-context.md @@ -2,15 +2,17 @@ '@tanstack/db': patch --- -Export `ExtractContext` type to enable extracting query result types from Query instances. +Export `QueryResult` helper type for easily extracting query result types (similar to Zod's `z.infer`). ```typescript -import { Query, ExtractContext, GetResult } from '@tanstack/db' +import { Query, QueryResult } from '@tanstack/db' const myQuery = new Query() .from({ users }) .select(({ users }) => ({ name: users.name })) -// Extract the result type: -type MyQueryResult = GetResult> +// Extract the result type - clean and simple! +type MyQueryResult = QueryResult ``` + +Also exports `ExtractContext` for advanced use cases where you need the full context type. diff --git a/packages/db/src/query/builder/index.ts b/packages/db/src/query/builder/index.ts index e7d2be0c4..c882db76a 100644 --- a/packages/db/src/query/builder/index.ts +++ b/packages/db/src/query/builder/index.ts @@ -29,6 +29,7 @@ import type { import type { CompareOptions, Context, + GetResult, GroupByCallback, JoinOnCallback, MergeContextForJoinCallback, @@ -864,6 +865,9 @@ export type ExtractContext = ? TContext : never +// Helper type to extract the result type from a QueryBuilder (similar to Zod's z.infer) +export type QueryResult = GetResult> + // Export the types from types.ts for convenience export type { Context, diff --git a/packages/db/src/query/index.ts b/packages/db/src/query/index.ts index c664117a8..524b4dcf1 100644 --- a/packages/db/src/query/index.ts +++ b/packages/db/src/query/index.ts @@ -11,6 +11,7 @@ export { type GetResult, type InferResultType, type ExtractContext, + type QueryResult, } from './builder/index.js' // Expression functions exports