Skip to content

Commit

Permalink
fix: validation errors type for optional nested schema objects
Browse files Browse the repository at this point in the history
re #51
  • Loading branch information
TheEdoRan committed Feb 6, 2024
1 parent 1623823 commit 94843fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/next-safe-action/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export type ErrorList = { _errors?: string[] } & {};

// Creates nested schema validation errors type using recursion.
export type SchemaErrors<S> = {
[K in keyof S]?: S[K] extends object ? Extend<ErrorList & SchemaErrors<S[K]>> : ErrorList;
[K in keyof S]?: S[K] extends object | null | undefined
? Extend<ErrorList & SchemaErrors<S[K]>>
: ErrorList;
} & {};

// This function is used to build the validation errors object from a list of validation issues.
Expand Down
4 changes: 3 additions & 1 deletion website/docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ Creates nested schema validation errors type using recursion. Used in [`Validati

```typescript
export type SchemaErrors<S> = {
[K in keyof S]?: S[K] extends object ? Extend<ErrorList & SchemaErrors<S[K]>> : ErrorList;
[K in keyof S]?: S[K] extends object | null | undefined
? Extend<ErrorList & SchemaErrors<S[K]>>
: ErrorList;
} & {};
```

Expand Down

0 comments on commit 94843fd

Please sign in to comment.