Skip to content

TypeScript generated types make autoincrement required #12703

Answered by austincrim
Krabba asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @Krabba 👋,

The model type itself will say that id is required unless it is explicitly marked as optional in your schema id 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,

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!

Replies: 7 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Krabba
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@austincrim
Comment options

Comment options

You must be logged in to vote
0 replies

This comment was marked as disruptive content.

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants