How do I type the `with` object part of a query builder if I extract it to it's own object?
I have a large
with
object that I reuse across multiple queries and I wanted to extract it to its own variable for reusing it. I typed this object with DBQueryConfig["with"]
which seems to make typescript happy but the return type is not inferred correctly. Am I missing something?
5 Replies
This is one way to do it https://github.com/drizzle-team/drizzle-orm/discussions/1483
GitHub
Relations input · drizzle-team drizzle-orm · Discussion #1483
I have a schema that looks like somewhat like this: export const employeesSchema = pgTable('employees', { firstName: varchar('first_name', { length: 256 }), lastName: varchar('l...
Thanks! @Angelelz
Maybe as a suggestion for the future, there could be kind of a utility type that would extract all of those generics, kind of how FieldValues and Path works in react-hook-form.
Yeah, there an open PR for this, should land soon
It seems typing it with the type you provided works but it does not help the type inference. I think the issue is that I am specifying specific columns in a nested relation. Any other ideas?
Yeah, you need to make your wrapper function generic. Take a look at the playground I put together in that discussion