Kirik
Kirik
TTCTheo's Typesafe Cult
Created by Kirik on 8/5/2023 in #questions
'id' does not exist in type 'UseTRPCMutationOptions<{ id: string; title?: string | undefined; ...
in pages/quest/[id].tsx
type Props = {
quest: QuestWithObjectives;
onClose: () => void;
};
export const QuestEditForm = ({ quest, onClose }: Props) => {
const { register, handleSubmit, formState } = useForm({
defaultValues: {
id: quest.quest.id,
title: quest.quest.title,
rating: quest.quest.rating,
...
},
});

const onSubmit: SubmitHandler<QuestUpdateInput> = async (data) => {

try {
api.quests.update.useMutation({
id: quest.quest.id, // ISSUE HERE
title: data.title,
rating: data.rating,
rating_denominator: data.rating_denominator,
reward_xp: data.reward_xp,
goal: data.goal,
target: data.target,});
onClose();
} catch (error) {
setUpdateError('Failed to update quest');
}
};
type Props = {
quest: QuestWithObjectives;
onClose: () => void;
};
export const QuestEditForm = ({ quest, onClose }: Props) => {
const { register, handleSubmit, formState } = useForm({
defaultValues: {
id: quest.quest.id,
title: quest.quest.title,
rating: quest.quest.rating,
...
},
});

const onSubmit: SubmitHandler<QuestUpdateInput> = async (data) => {

try {
api.quests.update.useMutation({
id: quest.quest.id, // ISSUE HERE
title: data.title,
rating: data.rating,
rating_denominator: data.rating_denominator,
reward_xp: data.reward_xp,
goal: data.goal,
target: data.target,});
onClose();
} catch (error) {
setUpdateError('Failed to update quest');
}
};
My router:
update: privateProcedure
.input(
z.object({
id: z.string(),
title: z.string().min(1).max(280).optional(),
rating: z.number().min(1).max(5).optional(),
...
})
)
.mutation(async ({ ctx, input }) => {
const authorId = ctx.userId;
const { success } = await ratelimit.limit(authorId);
...
update: privateProcedure
.input(
z.object({
id: z.string(),
title: z.string().min(1).max(280).optional(),
rating: z.number().min(1).max(5).optional(),
...
})
)
.mutation(async ({ ctx, input }) => {
const authorId = ctx.userId;
const { success } = await ratelimit.limit(authorId);
...
I've also tried setting types for const onSubmit = async (data: Type) => { with
type Quest = RouterOutputs["quests"]["getOne"][0];
type QuestUpdateInput = {
id: string;
title?: string;
rating?: number;
...
objectives?: {
obj: string;
location: string;
ingredients: string;
requiredAmount: number;
}[];
};

type UseMutationType = typeof api.quests.update.useMutation;

type QuestUpdateMutationInput = Parameters<UseMutationType>[0];
type QuestUpdateMutation = ReturnType<typeof api.quests.update.useMutation>;
type Quest = RouterOutputs["quests"]["getOne"][0];
type QuestUpdateInput = {
id: string;
title?: string;
rating?: number;
...
objectives?: {
obj: string;
location: string;
ingredients: string;
requiredAmount: number;
}[];
};

type UseMutationType = typeof api.quests.update.useMutation;

type QuestUpdateMutationInput = Parameters<UseMutationType>[0];
type QuestUpdateMutation = ReturnType<typeof api.quests.update.useMutation>;
7 replies
TTCTheo's Typesafe Cult
Created by Kirik on 5/4/2023 in #questions
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
7 replies
TTCTheo's Typesafe Cult
Created by Kirik on 4/27/2023 in #questions
Custom Nested DB schema defaults or empty help
Field "objectiveIds" in model "Quest" can't be a list. The current connector does not support lists of primitive types. ?????? Objective and Quest are custom models here, one to many. How to many? Do I have to comma parsing? prisma + planetscale or should I do: objective Objective[] I miss my android room primitive lists and my wall of converters q.q
3 replies
TTCTheo's Typesafe Cult
Created by Kirik on 4/26/2023 in #questions
:x: tRPC failed on posts.create: Unauthorized -- from T3 Stack Tutorial tutorial
NOTICE: Unauthorized, not UNAUTHORIZED as thrown in enforceUserIsAuthed. Am confused as "Unauthorized" not found in files Followed most of the tutorial, then github. PrivateProcedure resolves as valid userID not null. also switched ssg for createServerSideHelpers() and white bg and snapped left in npm run dev, but fine on deployment; not sure why 🧐
6 replies