Skip to content

Commit

Permalink
refactor(types): move PrettyMerge type in utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Apr 19, 2024
1 parent cff3545 commit f7eb50c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
3 changes: 3 additions & 0 deletions packages/next-safe-action/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export type Prettify<T> = {
// Returns type or promise of type.
export type MaybePromise<T> = Promise<T> | T;

// Merges an object without printing "&".
export type PrettyMerge<S> = S extends infer U ? { [K in keyof U]: U[K] } : never;

// Infers output schema type in array of schemas.
export type InferArray<BAS extends readonly Schema[]> = {
[K in keyof BAS]: Infer<BAS[K]>;
Expand Down
5 changes: 1 addition & 4 deletions packages/next-safe-action/src/validation-errors.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { Infer, Schema } from "@typeschema/main";
import type { Prettify } from "./utils";

// Merges an object without printing "&".
type PrettyMerge<S> = S extends infer U ? { [K in keyof U]: U[K] } : never;
import type { Prettify, PrettyMerge } from "./utils";

// Object with an optional list of validation errors.
export type ErrorList = Prettify<{ _errors?: string[] }>;
Expand Down
20 changes: 11 additions & 9 deletions website/docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ type HookActionStatus = "idle" | "executing" | "hasSucceeded" | "hasErrored";
---
## Utility types
## Internal utility types
### `Prettify`
Expand All @@ -274,6 +274,14 @@ Returns type or promise of type.
export type MaybePromise<T> = Promise<T> | T;
```
### `PrettyMerge`
Merges an object without printing "&".
```typescript
type PrettyMerge<S> = S extends infer U ? { [K in keyof U]: U[K] } : never;
```
### `InferArray`
Infers output schema type in array of schemas.
Expand All @@ -294,13 +302,7 @@ export type InferInArray<BAS extends readonly Schema[]> = {
};
```
### `PrettyMerge`
Merges an object without printing "&".
```typescript
type PrettyMerge<S> = S extends infer U ? { [K in keyof U]: U[K] } : never;
```
## Internal validation errors types
### `ErrorList`
Expand All @@ -326,4 +328,4 @@ type SchemaErrors<S> = {
## TypeSchema library
`Infer`, `InferIn`, `Schema` types come from [TypeSchema](https://typeschema.com) library.
`Infer`, `InferIn`, `Schema` types used in this documentation come from [TypeSchema](https://typeschema.com) library.

0 comments on commit f7eb50c

Please sign in to comment.