© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
8 replies
html_extraordinaire

Are dynamic selects with type inference possible?

Title. I'm trying to add select statements conditionally. I'd like the function to return a properly typed query based on what I've passed. Is that possible?
.select<SelectedFields<PgColumn, PgTable>>({
  ...(opts.groupBy && { irrigationClientId: shrink.irrigationClientId }),
  shrink: sum(shrink.amount).mapWith(Number).as('shrink'),
})
.select<SelectedFields<PgColumn, PgTable>>({
  ...(opts.groupBy && { irrigationClientId: shrink.irrigationClientId }),
  shrink: sum(shrink.amount).mapWith(Number).as('shrink'),
})

This prevents errors but isn't really what I want.
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

withPagination type inference
Drizzle TeamDTDrizzle Team / help
2y ago
Invalid type inference when using helpers
Drizzle TeamDTDrizzle Team / help
14mo ago
Returned type inference when using tanstack query
Drizzle TeamDTDrizzle Team / help
2y ago
No type inference when specifying a reference.
Drizzle TeamDTDrizzle Team / help
2y ago