typeof inferSelect not supported
const ExampleTable = pgTable('example', t => ({
id: t.uuid().notNull().primaryKey().defaultRandom(),
example: t.varchar({ length: 256 }).notNull(),
}));
type Example = InferSelectModel<typeof ExampleTable>; // this cannot be used as an api type
When using drizzle $inferSelect i get the message: typeof with non-ident not yet supported...
Any workarounds while this feature is not here?
In the drizzle example they just hint at using your own DTOs, which is sub-optimal but it should work for now.
Yes, is the same case for Prisma.
yeah, I hope this issue get more attention
I am having the same problem
Running into the same issue using Drizzle, I'd love to see this working in the future. Having to declare the same type twice is a bit of a bummer since this is not something that I would have to do with other frameworks that I'd like to replace with Encore.ts.
Same issue (I believe) also when using Valibot to define requests (for validation purposes) and using InferInput<typeof MyRequestSchema> to get the type definition for Encore.
Why this issue is not getting any attention? While working on a large project it's painful to manage manual DTOs... I prefer drizzle-zod, z.infer<typeof...> why wouldn't it support it?
Why this issue is not getting any attention? While working on a large project it's painful to manage manual DTOs... I prefer drizzle-zod, z.infer<typeof...> why wouldn't it support it?
I do agree. Currently this is the main reason why I am not using encore in prod...
You can use DTOs just fine with Encore, you just can't expose them as part of the public API of your Encore endpoints. This is something we're working towards supporting, but it will take some time as we need to add support for more features of the TypeScript type system first.
That said, it's generally not a good idea to expose your database schema in your API, as you typically want them decoupled for security reasons anyway, and to have more fine-grained control over your API. In my experience defining a few additional types to represent your public API is not a huge lift in terms of effort, and also leads to better API design and better API documentation.
@eandre it's good to know that you're working on it! Just want to mention that even manually defining types for the public API doesn't always work:
const distanceUnits = ["m", "km", "mi"];
type TDistanceUnit = (typeof distanceUnits)[number];
Using TDistanceUnit in the public API of an encore endpoint fails with this error:
error: unsupported indexed access type operation: obj Union(
Union {
types: [],
},
) index Basic(
Number,
)
--> /path/to/hello.ts:9:22
|
9 | type TDistanceUnit = (typeof distanceUnits)[number];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Hopefully this will be covered by the work you're already doing 😃 .
Yes, is the same case for Prisma.
So is there any viable solution available now?