Prerequisites
Versions
"prisma": "^5.4.2",
"@prisma/client": "^5.4.2",
"prisma-json-types-generator": "^3.0.2",
Description
Hey
I've been trying to add a simple JSON array to keep track of server logs on my Prisma Schema, but I keep getting the following TS error
Type '{ push: { message: string; timestamp: string; }; }' is not assignable to type 'UpdateManyInput<ServerLog> | undefined'.
Types of property 'push' are incompatible.
Type '{ message: string; timestamp: string; }' is not assignable to type 'ServerLog[] | ((...items: ServerLog[]) => number) | undefined'.
Object literal may only specify known properties, and 'message' does not exist in type 'ServerLog[] | ((...items: ServerLog[]) => number)'.ts(2322)
Steps to Reproduce
This is my Prisma Schema:
generator json {
provider = "prisma-json-types-generator"
}
...
model MyModel {
...
/// [ServerLog]
logs Json[]
...
}
And my types.ts
file
namespace PrismaJson {
type ServerLog = {
timestamp: string; // Date ISO
message: string;
};
}
The namespace and types are generated successfully, but it seems that pushing values into an array has the incorrect type.
The following code gives me the error:
await ctx.prisma.mymodel.update({
where: {
id: input.id,
},
data: {
logs: {
push: {
message: "My Message Here",
timestamp: new Date().toISOString(),
},
},
},
});
To "remove" the error, I need to push an array instead of a single value like this:
await ctx.prisma.mymodel.update({
where: {
id: input.id,
},
data: {
logs: {
push: [
{
message: `My Message Here`,
timestamp: new Date().toISOString(),
},
],
},
},
});
Expected Behavior
I should be able to push a single value, similar to how scalar lists work in Prisma