TRPC type issue
I have a typing issue which I don't understand, I have this trpc create method
But I get this type error
This is the schema:
create: t.procedure
.input(createFileSchema)
.mutation(async ({ input, ctx }) => {
const userId = ctx.session?.user?.id
if (!userId) {
throw new Error('Not authenticated')
}
const file = await prisma?.file.create({
data: { // error
User: {
connect: {
id: userId,
},
},
...input,
},
})
return file
}), create: t.procedure
.input(createFileSchema)
.mutation(async ({ input, ctx }) => {
const userId = ctx.session?.user?.id
if (!userId) {
throw new Error('Not authenticated')
}
const file = await prisma?.file.create({
data: { // error
User: {
connect: {
id: userId,
},
},
...input,
},
})
return file
}),But I get this type error
Types of property 'userId' are incompatible.
Type 'string' is not assignable to type 'undefined'.ts(2322)
index.d.ts(5945, 5): The expected type comes from property 'data' which is declared here on type Types of property 'userId' are incompatible.
Type 'string' is not assignable to type 'undefined'.ts(2322)
index.d.ts(5945, 5): The expected type comes from property 'data' which is declared here on type This is the schema:
const createFileSchema = z.object({
id: z.string().nullish(),
userId: z.string(),
url: z.string().min(1, 'Url is required.'),
title: z.string().min(1, 'Title is required.'),
description: z.string().min(1, 'Description is required.').nullish(),
createdAt: z.string().nullish(),
updatedAt: z.string().nullish(),
})const createFileSchema = z.object({
id: z.string().nullish(),
userId: z.string(),
url: z.string().min(1, 'Url is required.'),
title: z.string().min(1, 'Title is required.'),
description: z.string().min(1, 'Description is required.').nullish(),
createdAt: z.string().nullish(),
updatedAt: z.string().nullish(),
})