Skip to content

Commit cf4251e

Browse files
committed
fix(types): correct validation error typing for arrays
re #351
1 parent 8cf61ca commit cf4251e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/next-safe-action/src/validation-errors.types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import type { Prettify } from "./utils.types";
55
type NotObject = number | string | boolean | bigint | symbol | null | undefined | any[];
66

77
// Object with an optional list of validation errors.
8-
type VEList = Prettify<{ _errors?: string[] }>;
8+
type VEList<K = undefined> = K extends any[] ? { _errors?: string[] }[] : { _errors?: string[] };
99

1010
// Creates nested schema validation errors type using recursion.
1111
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 ? Prettify<VEList<S[K]>> : Prettify<VEList> & SchemaErrors<S[K]>;
1313
} & {};
1414

1515
export type IssueWithUnionErrors = StandardSchemaV1.Issue & {
@@ -21,8 +21,8 @@ export type IssueWithUnionErrors = StandardSchemaV1.Issue & {
2121
*/
2222
export type ValidationErrors<S extends StandardSchemaV1 | undefined> = S extends StandardSchemaV1
2323
? StandardSchemaV1.InferOutput<S> extends NotObject
24-
? VEList
25-
: Prettify<VEList & SchemaErrors<StandardSchemaV1.InferOutput<S>>>
24+
? Prettify<VEList>
25+
: Prettify<VEList> & SchemaErrors<StandardSchemaV1.InferOutput<S>>
2626
: undefined;
2727

2828
/**

0 commit comments

Comments
 (0)