Open Faithfinder opened 2 years ago
Hey there!
Similar to the documentation here for writing an Array of Json
objects, you will have to specify the JsonObject
type when writing the data. For example:
import { PrismaClient, Prisma } from "../prisma/built";
const client = new PrismaClient();
interface UserMeta {
someObject?: SomeObjectProp;
}
interface SomeObjectProp {
prop1: string;
}
const meta: UserMeta = {};
client.user.create({
data: {
email: "email",
meta: meta as Prisma.JsonObject
}
});
You can always typecast as a Typescript workaround, sure. Typecasting should be last resort though, IMO, and ideally not an official way to work with a library.
I can reproduce the original problem with the latest version.
Bug description
When your input type definition has deeper objects, it can't be used as input for JSON type columns.
How to reproduce
Repro: https://codesandbox.io/s/prisma-json-input-type-bad-134mdg
Code copypaste:
Expected behavior
"Just works"
Prisma information
Irrelevant, repro included
Environment & setup
Every, it's a typescript problem.
Prisma Version