Skip to content

Commit 6b85ac1

Browse files
committed
Improve validation result type
1 parent aa1b80d commit 6b85ac1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/utils/types.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ export type InitialState<T> = {
4242
};
4343
};
4444

45-
export type ValidateResult<T> = {
46-
isValid: boolean;
47-
data: T | null;
48-
errors?: Partial<{ [K in keyof T]: T[K] }>;
49-
};
45+
export type ValidateResult<T> =
46+
| {
47+
isValid: true;
48+
data: T;
49+
}
50+
| {
51+
isValid: false;
52+
data: null;
53+
errors?: Partial<{ [K in keyof T]: T[K] }>;
54+
};
5055

5156
export type useFormErrors<T> = {
5257
[K in keyof T]?: string;
5358
};
59+
5460
export interface UseFormReturn<T> {
5561
data: T;
5662
state: IState<T>;

0 commit comments

Comments
 (0)