File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
packages/next-safe-action/src Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,6 @@ export type Prettify<T> = {
5
5
6
6
// Returns type or promise of type.
7
7
export type MaybePromise < T > = Promise < T > | T ;
8
+
9
+ // Returns type or array of type.
10
+ export type MaybeArray < T > = T | T [ ] ;
Original file line number Diff line number Diff line change 1
1
import type { Infer , InferIn , Schema } from "./adapters/types" ;
2
- import type { Prettify } from "./utils.types" ;
2
+ import type { MaybeArray , Prettify } from "./utils.types" ;
3
3
4
4
// Basic types and arrays.
5
5
type NotObject = number | string | boolean | bigint | symbol | null | undefined | any [ ] ;
6
6
7
7
// Object with an optional list of validation errors.
8
- type VEList = Prettify < { _errors ?: string [ ] } > ;
8
+ type VEList < K = undefined > = K extends any [ ] ? MaybeArray < { _errors ?: string [ ] } > : { _errors ?: string [ ] } ;
9
9
10
10
// Creates nested schema validation errors type using recursion.
11
11
type SchemaErrors < S > = {
12
- [ K in keyof S ] ?: S [ K ] extends NotObject ? VEList : Prettify < VEList & SchemaErrors < S [ K ] > > ;
12
+ [ K in keyof S ] ?: S [ K ] extends NotObject ? VEList < S [ K ] > : Prettify < VEList & SchemaErrors < S [ K ] > > ;
13
13
} & { } ;
14
14
15
15
/**
16
16
* Type of the returned object when validation fails.
17
17
*/
18
18
export type ValidationErrors < S extends Schema | undefined > = S extends Schema
19
19
? Infer < S > extends NotObject
20
- ? VEList
20
+ ? Prettify < VEList >
21
21
: Prettify < VEList & SchemaErrors < Infer < S > > >
22
22
: undefined ;
23
23
You can’t perform that action at this time.
0 commit comments