1
1
import type { GenericSchema , GenericSchemaAsync , InferInput , InferOutput } from "valibot" ;
2
2
import type { z } from "zod" ;
3
3
4
- export type Exists < T > = any extends T ? never : T ;
4
+ export type IfInstalled < T > = any extends T ? never : T ;
5
5
6
- export type Schema = Exists < z . ZodType > | Exists < GenericSchema > | Exists < GenericSchemaAsync > ;
6
+ export type Schema = IfInstalled < z . ZodType > | IfInstalled < GenericSchema > | IfInstalled < GenericSchemaAsync > ;
7
7
export type Infer < S extends Schema > =
8
- S extends Exists < z . ZodType >
8
+ S extends IfInstalled < z . ZodType >
9
9
? z . infer < S >
10
- : S extends Exists < GenericSchema >
10
+ : S extends IfInstalled < GenericSchema >
11
11
? InferOutput < S >
12
- : S extends Exists < GenericSchemaAsync >
12
+ : S extends IfInstalled < GenericSchemaAsync >
13
13
? InferOutput < S >
14
14
: never ;
15
15
export type InferIn < S extends Schema > =
16
- S extends Exists < z . ZodType >
16
+ S extends IfInstalled < z . ZodType >
17
17
? z . input < S >
18
- : S extends Exists < GenericSchema >
18
+ : S extends IfInstalled < GenericSchema >
19
19
? InferInput < S >
20
- : S extends Exists < GenericSchemaAsync >
20
+ : S extends IfInstalled < GenericSchemaAsync >
21
21
? InferInput < S >
22
22
: never ;
23
23
export type InferArray < BAS extends readonly Schema [ ] > = {
@@ -39,12 +39,12 @@ export interface ValidationAdapter {
39
39
data : unknown
40
40
) : Promise < { success : true ; data : Infer < S > } | { success : false ; issues : ValidationIssue [ ] } > ;
41
41
// zod
42
- validate < S extends z . ZodType > (
42
+ validate < S extends IfInstalled < z . ZodType > > (
43
43
schema : S ,
44
44
data : unknown
45
45
) : Promise < { success : true ; data : Infer < S > } | { success : false ; issues : ValidationIssue [ ] } > ;
46
46
// valibot
47
- validate < S extends GenericSchema | GenericSchemaAsync > (
47
+ validate < S extends IfInstalled < GenericSchema | GenericSchemaAsync > > (
48
48
schema : S ,
49
49
data : unknown
50
50
) : Promise < { success : true ; data : Infer < S > } | { success : false ; issues : ValidationIssue [ ] } > ;
0 commit comments