Skip to content

Commit 94843fd

Browse files
committedFeb 6, 2024
fix: validation errors type for optional nested schema objects
re #51
1 parent 1623823 commit 94843fd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎packages/next-safe-action/src/utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export type ErrorList = { _errors?: string[] } & {};
1818

1919
// Creates nested schema validation errors type using recursion.
2020
export type SchemaErrors<S> = {
21-
[K in keyof S]?: S[K] extends object ? Extend<ErrorList & SchemaErrors<S[K]>> : ErrorList;
21+
[K in keyof S]?: S[K] extends object | null | undefined
22+
? Extend<ErrorList & SchemaErrors<S[K]>>
23+
: ErrorList;
2224
} & {};
2325

2426
// This function is used to build the validation errors object from a list of validation issues.

‎website/docs/types.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ Creates nested schema validation errors type using recursion. Used in [`Validati
127127

128128
```typescript
129129
export type SchemaErrors<S> = {
130-
[K in keyof S]?: S[K] extends object ? Extend<ErrorList & SchemaErrors<S[K]>> : ErrorList;
130+
[K in keyof S]?: S[K] extends object | null | undefined
131+
? Extend<ErrorList & SchemaErrors<S[K]>>
132+
: ErrorList;
131133
} & {};
132134
```
133135

0 commit comments

Comments
 (0)
Please sign in to comment.