X Tutup
Skip to content

Commit 1535bad

Browse files
committed
feat: infer type produced by standard schema
1 parent bfa71f2 commit 1535bad

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/types.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { z } from 'zod'
21
import type { ValidateFn } from '@poppinss/validator-lite'
32
import type { StandardSchemaV1 } from '@standard-schema/spec'
3+
import type { z } from 'zod'
44

55
/**
66
* Schema defined by the user
@@ -19,22 +19,11 @@ export type FullPluginOptions = (
1919
| { validator: 'standard'; schema: StandardSchema }
2020
) & { debug?: boolean; configFile?: string }
2121

22-
/**
23-
* Contract for schema definition for poppins validator
24-
*/
2522
export type PoppinsSchema = RecordViteKeys<ValidateFn<any>>
26-
27-
/**
28-
* Contract for schema definition for zod validator
29-
*/
3023
export type ZodSchema = RecordViteKeys<z.ZodType<any, any>>
31-
32-
/**
33-
* Contract for schema definition for standard-schema validator
34-
*/
3524
export type StandardSchema = RecordViteKeys<StandardSchemaV1>
3625

37-
export type Schema = PoppinsSchema | ZodSchema
26+
export type Schema = PoppinsSchema | ZodSchema | StandardSchema
3827

3928
/**
4029
* Infer the schema type from the plugin options
@@ -50,7 +39,9 @@ type EnvValue<Fn> = Fn extends (...args: any) => any
5039
? ReturnType<Fn>
5140
: Fn extends z.ZodType
5241
? z.infer<Fn>
53-
: never
42+
: Fn extends StandardSchemaV1
43+
? StandardSchemaV1.InferOutput<Fn>
44+
: never
5445

5546
/**
5647
* Augment the import.meta.env object with the values returned by the schema validator

0 commit comments

Comments
 (0)
X Tutup