Skip to content

Commit b61c9cd

Browse files
committed
refactor(types): separate valibot generic schema types
1 parent 6e04a2c commit b61c9cd

File tree

1 file changed

+22
-10
lines changed
  • packages/next-safe-action/src/adapters

1 file changed

+22
-10
lines changed

packages/next-safe-action/src/adapters/types.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,33 @@ import type { z } from "zod";
66

77
export type IfInstalled<T> = any extends T ? never : T;
88

9-
export type Schema = IfInstalled<z.ZodType> | IfInstalled<GenericSchema | GenericSchemaAsync> | IfInstalled<YupSchema>;
9+
export type Schema =
10+
| IfInstalled<z.ZodType>
11+
| IfInstalled<GenericSchema>
12+
| IfInstalled<GenericSchemaAsync>
13+
| IfInstalled<YupSchema>;
1014

1115
export type Infer<S extends Schema> =
1216
S extends IfInstalled<z.ZodType>
1317
? z.infer<S>
14-
: S extends IfInstalled<GenericSchema | GenericSchemaAsync>
18+
: S extends IfInstalled<GenericSchema>
1519
? InferOutput<S>
16-
: S extends IfInstalled<YupSchema>
17-
? InferType<S>
18-
: never;
20+
: S extends IfInstalled<GenericSchemaAsync>
21+
? InferOutput<S>
22+
: S extends IfInstalled<YupSchema>
23+
? InferType<S>
24+
: never;
1925

2026
export type InferIn<S extends Schema> =
2127
S extends IfInstalled<z.ZodType>
2228
? z.input<S>
23-
: S extends IfInstalled<GenericSchema | GenericSchemaAsync>
29+
: S extends IfInstalled<GenericSchema>
2430
? InferInput<S>
25-
: S extends IfInstalled<YupSchema>
26-
? InferType<S>
27-
: never;
31+
: S extends IfInstalled<GenericSchemaAsync>
32+
? InferInput<S>
33+
: S extends IfInstalled<YupSchema>
34+
? InferType<S>
35+
: never;
2836

2937
export type InferArray<BAS extends readonly Schema[]> = {
3038
[K in keyof BAS]: Infer<BAS[K]>;
@@ -50,7 +58,11 @@ export interface ValidationAdapter {
5058
data: unknown
5159
): Promise<{ success: true; data: Infer<S> } | { success: false; issues: ValidationIssue[] }>;
5260
// valibot
53-
validate<S extends IfInstalled<GenericSchema | GenericSchemaAsync>>(
61+
validate<S extends IfInstalled<GenericSchema>>(
62+
schema: S,
63+
data: unknown
64+
): Promise<{ success: true; data: Infer<S> } | { success: false; issues: ValidationIssue[] }>;
65+
validate<S extends IfInstalled<GenericSchemaAsync>>(
5466
schema: S,
5567
data: unknown
5668
): Promise<{ success: true; data: Infer<S> } | { success: false; issues: ValidationIssue[] }>;

0 commit comments

Comments
 (0)