help with basic ts error
prisma schema
zod schema
tRPC route
model User {
id Int @id @default(autoincrement())
/// @zod.string.min(2, { message: "Must be between 2-12 characters" }).max(12, { message: "Must be between 2-12 characters" })
username String @unique
password String
settings Json?
role Role @default(USER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// one to many
posts Post[] @relation("posts")
comments Comment[] @relation("comments")
// many to many
likedPosts Post[] @relation("likedPosts")
dislikedPosts Post[] @relation("dislikedPosts")
likedComments Comment[] @relation("likedComments")
dislikedComments Comment[] @relation("dislikedComments")
}
model User {
id Int @id @default(autoincrement())
/// @zod.string.min(2, { message: "Must be between 2-12 characters" }).max(12, { message: "Must be between 2-12 characters" })
username String @unique
password String
settings Json?
role Role @default(USER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// one to many
posts Post[] @relation("posts")
comments Comment[] @relation("comments")
// many to many
likedPosts Post[] @relation("likedPosts")
dislikedPosts Post[] @relation("dislikedPosts")
likedComments Comment[] @relation("likedComments")
dislikedComments Comment[] @relation("dislikedComments")
}
export const z_user = z.object({
username: z.string()
.nonempty({ message: "This field is required" })
.min(2, { message: "Must be between 2-12 characters" })
.max(12, { message: "Must be between 2-12 characters" }),
password: z.string()
.nonempty({ message: "This field is required" })
.min(2, { message: "Must be between 2-12 characters" })
.max(12, { message: "Must be between 2-12 characters" }),
}).strict()
export const z_user = z.object({
username: z.string()
.nonempty({ message: "This field is required" })
.min(2, { message: "Must be between 2-12 characters" })
.max(12, { message: "Must be between 2-12 characters" }),
password: z.string()
.nonempty({ message: "This field is required" })
.min(2, { message: "Must be between 2-12 characters" })
.max(12, { message: "Must be between 2-12 characters" }),
}).strict()
updateUser:
t.procedure
.input(z_user.extend({ id: z.number() }))
.mutation(async ({ input }) => {
return prisma.user.update({ where: { input.id }, data: input })
})
updateUser:
t.procedure
.input(z_user.extend({ id: z.number() }))
.mutation(async ({ input }) => {
return prisma.user.update({ where: { input.id }, data: input })
})
4 Replies
error (in screenshot)
Type '{ input: { username: string; password: string; id: number; }; "": any; }' is not assignable to type 'UserWhereUniqueInput'.
Object literal may only specify known properties, and 'input' does not exist in type 'UserWhereUniqueInput'.ts(2322)
index.d.ts(1919, 5): The expected type comes from property 'where' which is declared here on type '{ select?: UserSelect | null | undefined; include?: UserInclude | null | undefined; data: (Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput); where: UserWhereUniqueInput; }'
(property) input: {
username: string;
password: string;
id: number;
}
Type '{ input: { username: string; password: string; id: number; }; "": any; }' is not assignable to type 'UserWhereUniqueInput'.
Object literal may only specify known properties, and 'input' does not exist in type 'UserWhereUniqueInput'.ts(2322)
index.d.ts(1919, 5): The expected type comes from property 'where' which is declared here on type '{ select?: UserSelect | null | undefined; include?: UserInclude | null | undefined; data: (Without<UserUpdateInput, UserUncheckedUpdateInput> & UserUncheckedUpdateInput) | (Without<...> & UserUpdateInput); where: UserWhereUniqueInput; }'
(property) input: {
username: string;
password: string;
id: number;
}
you're just passing a value, you need a key as well
where: { id: input.id }
truuuuuuuuuuuuuuuuuuuuuuue