diff --git a/packages/next-safe-action/src/adapters/types.ts b/packages/next-safe-action/src/adapters/types.ts index 23e9dc85..12a8e6c7 100644 --- a/packages/next-safe-action/src/adapters/types.ts +++ b/packages/next-safe-action/src/adapters/types.ts @@ -1,23 +1,23 @@ import type { GenericSchema, GenericSchemaAsync, InferInput, InferOutput } from "valibot"; import type { z } from "zod"; -export type Exists = any extends T ? never : T; +export type IfInstalled = any extends T ? never : T; -export type Schema = Exists | Exists | Exists; +export type Schema = IfInstalled | IfInstalled | IfInstalled; export type Infer = - S extends Exists + S extends IfInstalled ? z.infer - : S extends Exists + : S extends IfInstalled ? InferOutput - : S extends Exists + : S extends IfInstalled ? InferOutput : never; export type InferIn = - S extends Exists + S extends IfInstalled ? z.input - : S extends Exists + : S extends IfInstalled ? InferInput - : S extends Exists + : S extends IfInstalled ? InferInput : never; export type InferArray = { @@ -39,12 +39,12 @@ export interface ValidationAdapter { data: unknown ): Promise<{ success: true; data: Infer } | { success: false; issues: ValidationIssue[] }>; // zod - validate( + validate>( schema: S, data: unknown ): Promise<{ success: true; data: Infer } | { success: false; issues: ValidationIssue[] }>; // valibot - validate( + validate>( schema: S, data: unknown ): Promise<{ success: true; data: Infer } | { success: false; issues: ValidationIssue[] }>; diff --git a/packages/next-safe-action/src/adapters/valibot.ts b/packages/next-safe-action/src/adapters/valibot.ts index 016cc72a..dad8ab7d 100644 --- a/packages/next-safe-action/src/adapters/valibot.ts +++ b/packages/next-safe-action/src/adapters/valibot.ts @@ -1,8 +1,8 @@ import { getDotPath, safeParseAsync, type GenericSchema, type GenericSchemaAsync } from "valibot"; -import type { Infer, ValidationAdapter } from "./types"; +import type { IfInstalled, Infer, ValidationAdapter } from "./types"; class ValibotAdapter implements ValidationAdapter { - async validate(schema: S, data: unknown) { + async validate>(schema: S, data: unknown) { const result = await safeParseAsync(schema, data); if (result.success) { diff --git a/packages/next-safe-action/src/adapters/zod.ts b/packages/next-safe-action/src/adapters/zod.ts index 70442c40..cf49dcae 100644 --- a/packages/next-safe-action/src/adapters/zod.ts +++ b/packages/next-safe-action/src/adapters/zod.ts @@ -1,10 +1,10 @@ import type { z } from "zod"; -import type { Infer, ValidationAdapter } from "./types"; +import type { IfInstalled, Infer, ValidationAdapter } from "./types"; export type ZodSchema = z.ZodType; class ZodAdapter implements ValidationAdapter { - async validate(schema: S, data: unknown) { + async validate>(schema: S, data: unknown) { const result = await schema.safeParseAsync(data); if (result.success) {