This repository was archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
This repository was archived by the owner on Aug 18, 2021. It is now read-only.
Support TS generics #19
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
- I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
Currently some functions does not support generics so we cannot leverage the power of typescript on returning data.
Take for example this one --> https://2x.antdv.com/components/form/#components-form-demo-useform
I have an interface
interface User {
email: string
firstName: string
lastName: string
}
I want to control the validation to return that type
const data = await validate<User>()
So I am sure that the validate function just return the correct type.
What does the proposed API look like?
Looking in the generated type files I see
declare function useForm(modelRef: Props, rulesRef?: Props, options?: {
immediate?: boolean;
deep?: boolean;
validateOnRuleChange?: boolean;
debounce?: DebounceSettings;
}): {
modelRef: Props;
rulesRef: Props;
initialModel: Props;
validateInfos: validateInfos;
resetFields: () => void;
validate: (names?: string | string[], option?: validateOptions) => Promise<any>;
validateField: (name?: string, value?: any, rules?: [Record<string, unknown>], option?: validateOptions) => Promise<any>;
mergeValidateInfo: (items: validateInfo | validateInfo[]) => validateInfo;
};
Where validate and validateField are set to Promise<any> instead of some thing like
validate: (names?: string | string[], option?: validateOptions)<T = any> => Promise<T>;
validateField: (name?: string, value?: any, rules?: [Record<string, unknown>], option?: validateOptions)<T = any> => Promise<T>;
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request