The TypeScript type for ModelWhereUniqueInput when...
# prisma-client
b
The TypeScript type for ModelWhereUniqueInput when model only has a single unique field still marks that single field as optional. Is it somehow possible to make that one field required? Maybe a generator flag?
Copy code
export type ModelWhereUniqueInput = {
  id?: string
}
@Ryan do you maybe have an idea? (After the weekend is soon enough though...)
r
The reason for this is that there can be multiple unique fields and you might only want to specify one of them, which is why all the fields are optional so this is by design. If you’d still like to open a request to enable this, you can do this here 🙂
b
my model only specifies a single unique field (
id
) - so I was wondering if there was a check for that case - and one could automatically make that field required then. I suppose the more granular type definition would be a union of types that have exactly one of the model's unique props each and make it required.
Copy code
model User {
id String @id
email String @unique
}
Copy code
type UserWhereUniqueInput = { id: string } | { email: string }
thanks for your input. I've opened an issue
💯 1