TypeScript generated types make autoincrement required #12703
-
Hi, For example, an ID field in my model that will autoincrement:
Will give me this type in
What I want to receive is:
Should this not be optional since if you skip to provide it, it will auto increment if it's not defined in the Client API? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
Hey @Krabba 👋, The model type itself will say that However, Prisma also generates separate types for creating or updating a model, and these types will have For this model User {
id Int @id @default(autoincrement())
name String?
} Prisma will generate types like these: export type UserUncheckedCreateInput = {
id?: number
name?: string | null
} Let me know if I can clarify any further! |
Beta Was this translation helpful? Give feedback.
-
Hi @austincrim You can't, or I can't atleast, mark an However, I wasn't aware of the GIGANTIC variety of types to choose from when using the generated types in TypeScript. Cool stuff! Thank you for your help. 🛩️ |
Beta Was this translation helpful? Give feedback.
-
Well the problem still exists. The autoincrement fields are made mandatory by typescript and yes one cannot make those optional with ? either. Does this have any solution yet? |
Beta Was this translation helpful? Give feedback.
-
I am no longer able to, or was never able to import I can only import my table name types from that file (which is weird), but not the others surrounding. I'm using |
Beta Was this translation helpful? Give feedback.
-
Same issue but with uuid |
Beta Was this translation helpful? Give feedback.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
-
You can use Prisma.userCreateInput for a user model This wont require the id field. You can do this for any Prisma created model. So say you had a model FizzBuzz, the type Prisma.FizzBuzzCreateInput will be genereated. |
Beta Was this translation helpful? Give feedback.
Hey @Krabba 👋,
The model type itself will say that
id
is required unless it is explicitly marked as optional in your schemaid Int?
.However, Prisma also generates separate types for creating or updating a model, and these types will have
id
marked as optional.For this
User
model,Prisma will generate types like these:
Let me know if I can clarify any further!