fix(types): flatten tRPC Zod schema types to resolve TS2589 inference depth errors
Cast Zod schemas with .refine()/.superRefine() to z.ZodType<InferredType> at the procedure level. This short-circuits TypeScript's deep type recursion through tRPC's middleware chain, eliminating 4 of 5 @ts-expect-error TS2589 suppressions in web components (VacationModal, ProjectModal, UsersClient, CountriesClient). Applied same pattern to allocation, timeline, staffing, dashboard, project, and resource query/mutation procedures to reduce client-side type depth. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { validateAvailability } from "@capakraken/engine";
|
||||
import {
|
||||
type AllocationConflictCheckResult,
|
||||
type WeekdayAvailability,
|
||||
import type {
|
||||
AllocationConflictCheckResult,
|
||||
AllocationStatus,
|
||||
WeekdayAvailability,
|
||||
} from "@capakraken/shared";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
@@ -24,7 +25,7 @@ export const allocationConflictProcedures = {
|
||||
* Read-only — no mutations.
|
||||
*/
|
||||
checkConflicts: managerProcedure
|
||||
.input(CheckConflictsInputSchema)
|
||||
.input(CheckConflictsInputSchema as z.ZodType<z.infer<typeof CheckConflictsInputSchema>>)
|
||||
.query(async ({ ctx, input }): Promise<AllocationConflictCheckResult> => {
|
||||
const resource = await ctx.db.resource.findUnique({
|
||||
where: { id: input.resourceId },
|
||||
@@ -39,8 +40,7 @@ export const allocationConflictProcedures = {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "Resource not found" });
|
||||
}
|
||||
|
||||
const fallbackDailyHours =
|
||||
(resource.country?.dailyWorkingHours ?? 8) * (resource.fte ?? 1);
|
||||
const fallbackDailyHours = (resource.country?.dailyWorkingHours ?? 8) * (resource.fte ?? 1);
|
||||
const availability = (resource.availability as WeekdayAvailability | null) ?? {
|
||||
monday: fallbackDailyHours,
|
||||
tuesday: fallbackDailyHours,
|
||||
@@ -82,7 +82,12 @@ export const allocationConflictProcedures = {
|
||||
input.endDate,
|
||||
input.hoursPerDay,
|
||||
availability,
|
||||
existingAssignments as { startDate: Date; endDate: Date; hoursPerDay: number; status: import("@capakraken/shared").AllocationStatus }[],
|
||||
existingAssignments as {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
hoursPerDay: number;
|
||||
status: AllocationStatus;
|
||||
}[],
|
||||
);
|
||||
|
||||
// Compute max overbook percentage for the worst day
|
||||
@@ -90,9 +95,7 @@ export const allocationConflictProcedures = {
|
||||
for (const conflict of availabilityResult.conflicts) {
|
||||
const totalBooked = conflict.existingHours + conflict.requestedHours;
|
||||
const overbookPct =
|
||||
conflict.availableHours > 0
|
||||
? ((totalBooked / conflict.availableHours) - 1) * 100
|
||||
: 100;
|
||||
conflict.availableHours > 0 ? (totalBooked / conflict.availableHours - 1) * 100 : 100;
|
||||
if (overbookPct > maxOverbookPercent) maxOverbookPercent = overbookPct;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user