-
Hi, Yesterday, when I restarted coding, all my props had the type "any." It was impossible to know what happened. I didn't install any new packages. I tried rolling back to my last commit, and after VS Code loaded, all the type errors appeared... I am building my server action with V6. This is my SafeActionClient import { createSafeActionClient } from "next-safe-action";
export const safeAction = createSafeActionClient(); This is my SafeAuthActionClient import { auth } from "@/auth";
import { UserSchema } from "@/schema/UserSchema";
import { createSafeActionClient } from "next-safe-action";
import { prisma } from "./prisma";
export const safeAuthAction = createSafeActionClient({
async middleware() {
const session = await auth();
if (!session?.user?.id) {
throw new Error("Session not found!");
}
const user = UserSchema.parse(
await prisma.user.findUnique({
where: { id: session.user.id },
include: {
role: true,
},
}),
);
return {
userId: user.id,
companyId: user?.currentCompany,
currentUser: user,
};
},
}); this is an example of server action "use server";
import { prisma } from "@/lib/prisma";
import { safeAuthAction } from "@/lib/safeAuthAction";
import { InterventionSchema } from "@/schema/InterventionSchema";
import { ValueSchema } from "@/schema/ValueSchema";
import { revalidatePath } from "next/cache";
import { z } from "zod";
export const createIntervention = safeAuthAction(
z.object({
values: z.array(ValueSchema),
path: z.string(),
}),
async ({ values, path }, { userId, companyId }) => {
const intervention = await prisma.intervention.create({
data: {
userId,
companyId,
values,
},
});
revalidatePath(path);
return InterventionSchema.parse(intervention);
},
); In this query, values and path as "any" as types... |
Beta Was this translation helpful? Give feedback.
Answered by
TheEdoRan
Jul 9, 2024
Replies: 1 comment 5 replies
-
You're probably using TypeScript 5.5. Unfortunately TypeSchema is not compatible with it, so rollback to 5.4. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your VS Code is probably using the default editor TS version. Use the workspace one and then reload the window, the error should go away.