Type error on 1-1 relationships
See original GitHub issueI have the given (simplified) schema where User
and Keychain
have a 1-1 relationship:
datasource db {
provider = "postgresql"
url = env("DATABASE_URI")
}
generator client {
provider = "prisma-client-js"
}
generator zod {
provider = "zod-prisma"
output = "./schemas"
relationModel = true
}
model User {
id String @id @default(uuid())
keychain Keychain?
}
model Keychain {
userID String @id
owner User @relation(fields: [userID], references: [id])
}
Those relationships have to be defined as nullable on one end, but the generated user schema generates a TypeScript error:
import * as z from "zod"
import { CompleteKeychain, relatedKeychainSchema } from "./index"
export const userSchema = z.object({
id: z.string()
})
export interface CompleteUser extends z.infer<typeof userSchema> {
keychain: CompleteKeychain | null
}
/**
* relatedUserSchema contains all relations on your model in addition to the scalars
*
* NOTE: Lazy required in case of potential circular dependencies within schema
*/
export const relatedUserSchema: z.ZodSchema<CompleteUser> = z.lazy(() => userSchema.extend({
keychain: relatedKeychainSchema.nullish(), // <= ts2322
}))
Removing the .nullish()
modifier for the keychain in relatedUserSchema
fixes the issue.
Edit: using .nullable()
there works too, which was what was used before.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Type I & Type II Errors | Differences, Examples, Visualizations
In statistics, a Type I error is a false positive conclusion, while a Type II error is a false negative conclusion.
Read more >Type II Error - Definition, How to Avoid, and Example
The type II error is also known as a false negative. The type II error has an inverse relationship with the power of...
Read more >What are Type I and Type II Errors? - Simply Psychology
A type II error is also known as a false negative and occurs when a researcher fails to reject a null hypothesis which...
Read more >Can anyone help me figure out why my relationships are ...
I'm getting an error message that says "relationships must be on the same number of fields with the same data types". I can't...
Read more >Explain the relationship between TYPE I error and Type II error.
A type I error covers those errors where the null hypothesis, which accurately describes the data, is rejected. This complements the type II...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
0.5.2 has been published with a fix for this.
I’ve got this too. Replacing
.nullish()
with.nullable()
in the related Models fixed the typescript error. It looks like its because it could beundefined