© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
nk

SelectionMap with nested objects

Hi, I'm trying to re-create the db.query({ with: {} }) but it's not working with nested objects because I don't know the type.

For example:

// Note the "any", which should be the type I'm missing.
type SelectionMap<T extends ProductSelect> = {
  [K in keyof T]: T[K] extends true ? { [key: string]: any } : {};
};

export namespace ProductSearchService {
  function getSelect<T extends ProductSelect>(select: T): SelectionMap<T> {
    return {
      ...(select.test
        ? {
            testA: {
              id: testTable.id,
              name: testTable.name,
            },
            testB: {
              id: testTable2.id,
              name: testTable2.name,
            },
          }
        : {}),
// Note the "any", which should be the type I'm missing.
type SelectionMap<T extends ProductSelect> = {
  [K in keyof T]: T[K] extends true ? { [key: string]: any } : {};
};

export namespace ProductSearchService {
  function getSelect<T extends ProductSelect>(select: T): SelectionMap<T> {
    return {
      ...(select.test
        ? {
            testA: {
              id: testTable.id,
              name: testTable.name,
            },
            testB: {
              id: testTable2.id,
              name: testTable2.name,
            },
          }
        : {}),


the product.testA will work, but product.testA.id will not, which is what I'm trying to fix.
I imagine there is a helper for this?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Inferring types for nested objects
Drizzle TeamDTDrizzle Team / help
2y ago
Mapping Query Builder Results to Nested Objects in Drizzle
Drizzle TeamDTDrizzle Team / help
15mo ago
Help with nested query
Drizzle TeamDTDrizzle Team / help
2y ago
Error with Nested Transactions
Drizzle TeamDTDrizzle Team / help
2y ago