-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript compilation fails when calling create()
with model having Json
field
#10741
Comments
@janpio Basically the issue is here: https://www.prisma.io/docs/concepts/components/prisma-client/crud#create-a-single-record-using-generated-types Why the user on that example is created with type Prisma.UserCreateInput okay. But if you already have a user of type Prisma.User shouldn't this work just fine at least in most examples. Basically we now have an issue where we have users of type Prisma.User but they can't be used to call like createMany without (user as Prisma.CreateManyInput) or (user as DeleteManyInput) also DeleteManyInput works just fine for createMany but simple ** Model User ** type doesn't work although has the same keys... Seems Prisma.JsonValue | null of "Model User" and CreateManyInput of NullableJsonNullValueInput | InputJsonValue are conflicting... Yeah just that in our model it can be "null" or "missing" but of course for input can't be null or need to be set to Prisma.DbNull etc... Trying to come up with a solution. Required only a little trickery to force NonNullable field. |
I have the same issue on my project. Did you find out a solution/workaround besides typing as |
You can make your own type from the Prisma generated type where you override the JSON field to be "NonNullable"
|
Excuse my ignorance, but what if the Isn't the override "unsyncing" the reality? |
It depends what you do in TS side. It works in our case. |
how to add the type? |
Any chance this gets fixed any time soon ? 🙏 In my case I experience it with nullable Json fields as well.
|
The model field is of type:
Seems this is due to JSON null being ambiguous and there being 3 enums for NULL.... Null in the context of create/update should be indeed Suggestion:
|
Json
field
Same with if using Edit: |
Json
fieldcreate()
with model having Json
field
Bug description
We have been using Prisma now for few weeks, and noticed that for some reason we are not able to call create/createMany with Prisma model instance with Json field, as TypeScript compilation fails.
How to reproduce
index.ts
Compilation error from tsc
Expected behavior
No response
Prisma information
schema.prisma
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: