-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
46 lines (35 loc) · 1.18 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Dispatch, SetStateAction } from 'react';
export interface CallbackFn {
(state?: any): void;
}
export interface GetStateFn<T> {
(): T;
}
export interface SetStateFn<T> {
(newState: Partial<T>, callback?: CallbackFn): void;
}
export interface SetSingleStateFn<T> {
(partialStates: Partial<T>, callback?: CallbackFn): void;
}
export type KeyOf<T> = Extract<keyof T, string>
export type CancelDebounceFn = () => void;
export type IntervalClear = () => void;
export type IntervalFn = (fn: () => void, delay: number | undefined, immediate?: boolean) => IntervalClear;
export type IntervalHook = [IntervalFn, IntervalClear];
export type FormField<T, D extends FormDataType> = {
value: T;
required?: boolean;
validator?: (value: T, data: D) => string | null | undefined;
message?: string;
};
export type FormDataType = {
[key: string]: any;
};
export type FormSubmitResult<T extends FormDataType> = T | { [K in keyof T]?: string };
export type UseFormChangeResult<T extends Record<string, FormField<any, FormDataType>>> = [
FormDataType,
(formItem: Partial<FormDataType>) => void,
{ [K in keyof T]?: string },
() => Promise<FormSubmitResult<FormDataType>>,
() => void
];