Type 'string | null' is not assignable to type 'string | undefined'.

Argument of type 'Quest' is not assignable to parameter of type '{ id: string; title?: string | undefined; rating?: number | undefined; rating_denominator?: number | undefined; reward_xp?: number | undefined; goal?: string | undefined; target?: Date | undefined; ... 7 more ...; objectives?: { ...; }[] | undefined; }'. Types of property 'description' are incompatible. Type 'string | null' is not assignable to type 'string | undefined'. Type 'null' is not assignable to type 'string | undefined'.ts(2345) I'm getting type directly from: type Quest = RouterOutputs["quests"]["getById"]; and update procedure is below... also lmk if I'm updating custom types wrong
4 Replies
Kirik
KirikOP2y ago
update: privateProcedure
.input(
z.object({
id: z.string(),
title: z.string().min(1).max(280).optional(),
rating: z.number().min(1).max(5).optional(),
rating_denominator: z.number().min(1).optional(),
reward_xp: z.number().min(1).optional(),
goal: z.string().optional(),
target: z.date().optional(),
description: z.string().optional(),
region: z.string().optional(),
location: z.string().optional(),
imageUrl: z.string().optional(),
tagline: z.string().optional(),
ingredients: z.string().optional(),
reward: z.string().optional(),
objectives: z.array(
z.object({
obj: z.string(),
location: z.string(),
ingredients: z.string(),
requiredAmount: z.number(),
})
).optional(),
})
)
.mutation(async ({ ctx, input }) => {
const authorId = ctx.userId;

const { success } = await ratelimit.limit(authorId);

if (!success) throw new TRPCError({ code: "TOO_MANY_REQUESTS" });

const quest = await ctx.prisma.quest.update({
where: { id: input.id },
data: {
title: input.title,
rating: input.rating,
rating_denominator: input.rating_denominator,
reward_xp: input.reward_xp,
goal: input.goal,
target: input.target,
description: input.description,
region: input.region,
location: input.location,
imageUrl: input.imageUrl,
tagline: input.tagline,
ingredients: input.ingredients,
reward: input.reward,

},

});
/* const objectives = await ctx.prisma.objective.update({data: {create:
{obj :input.objectives}); */
if (!quest) throw new TRPCError({ code: "NOT_FOUND" });

return (await addUserDataToQuests([quest]))[0];

}),
update: privateProcedure
.input(
z.object({
id: z.string(),
title: z.string().min(1).max(280).optional(),
rating: z.number().min(1).max(5).optional(),
rating_denominator: z.number().min(1).optional(),
reward_xp: z.number().min(1).optional(),
goal: z.string().optional(),
target: z.date().optional(),
description: z.string().optional(),
region: z.string().optional(),
location: z.string().optional(),
imageUrl: z.string().optional(),
tagline: z.string().optional(),
ingredients: z.string().optional(),
reward: z.string().optional(),
objectives: z.array(
z.object({
obj: z.string(),
location: z.string(),
ingredients: z.string(),
requiredAmount: z.number(),
})
).optional(),
})
)
.mutation(async ({ ctx, input }) => {
const authorId = ctx.userId;

const { success } = await ratelimit.limit(authorId);

if (!success) throw new TRPCError({ code: "TOO_MANY_REQUESTS" });

const quest = await ctx.prisma.quest.update({
where: { id: input.id },
data: {
title: input.title,
rating: input.rating,
rating_denominator: input.rating_denominator,
reward_xp: input.reward_xp,
goal: input.goal,
target: input.target,
description: input.description,
region: input.region,
location: input.location,
imageUrl: input.imageUrl,
tagline: input.tagline,
ingredients: input.ingredients,
reward: input.reward,

},

});
/* const objectives = await ctx.prisma.objective.update({data: {create:
{obj :input.objectives}); */
if (!quest) throw new TRPCError({ code: "NOT_FOUND" });

return (await addUserDataToQuests([quest]))[0];

}),
Sturlen
Sturlen2y ago
it might be more helpful the show the entire router, as the code here seems to be missing the "getById" procedure metioned in the error. also using ```js at the top of your code snippets will add syntax highlighting for js
sheng2808
sheng28082y ago
where there is no quest description, you want it to be null or undefined? if you want it to be null, add .nullable behind your zod input, if you want it to be undefined, then modify your quest so that it returns undefined when there is no description
sheng2808
sheng28082y ago
GitHub
GitHub - colinhacks/zod: TypeScript-first schema validation with st...
TypeScript-first schema validation with static type inference - GitHub - colinhacks/zod: TypeScript-first schema validation with static type inference
Want results from more Discord servers?
Add your server