How do I import a type?
This might be something I'm just totally overlooking, but I'm used to prisma where you can just import any schema you've defined as a type.
For example, if I have a table
posts
, I'd expecect to be able to import a Post
type to be used in one of my child components.
Is this possible with Drizzle? Or have you all found it to be unnecessary11 Replies
import from your .ts schema file ?
@behalf but when I import, I'm importing the schema, not the type
im not really good at ts but can't u just use the import type from "schema"
@behalf I don't think so, can you provide an example?
The schemas defined in schema.ts are not types, at least they don't appear to work like regular types when I try to use them.
You want to use typescript interface of your defined table schema right?
Do it like this:
myEntity
being the table description in your schema.@arwancer yup exactly!
@fermentfan oh thank you this is super helpful - I'm surprised that drizzle doesn't have a way to do this automatically like prismas
generate
I think it’s a fundamental architectural difference in drizzle vs Prisma as one works by using Typescript only, while Prisma is generating code in your project root.
yeah that's fair, but I guess it would be nice to have a command that automatically generated all the types just by way of generating these lines :
export type myEntityType = InferModel<typeof myEntity>;
feature request I guess!I agree on this. Now the InferModel is also depreciated. 😢
for anyone like me that got here from search: https://github.com/drizzle-team/drizzle-orm/releases/tag/0.28.3
Its deprecated, but you can now use
InferSelectModel
insteadGitHub
Release 0.28.3 · drizzle-team/drizzle-orm
UPDATE: The 0.28.3 release introduced a bug with types specifically for esm projects. Everything works as expected with cjs. If you're experiencing any type-related bugs as described in #1090, ...