Merge pull request #15355 from ant-design/form-generic-values

Add generic type to form values
This commit is contained in:
偏右 2019-03-13 10:37:00 +08:00 committed by GitHub
commit 91025841ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,7 +75,7 @@ export type ValidationRule = {
validator?: (rule: any, value: any, callback: any, source?: any, options?: any) => any;
};
export type ValidateCallback = (errors: any, values: any) => void;
export type ValidateCallback<V> = (errors: any, values: V) => void;
export type GetFieldDecoratorOptions = {
/** 子节点的值的属性,如 Checkbox 的是 'checked' */
@ -134,7 +134,7 @@ export type ValidateFieldsOptions = {
};
// function create
export type WrappedFormUtils = {
export type WrappedFormUtils<V = any> = {
/** 获取一组输入控件的值,如不传入参数,则获取全部组件的值 */
getFieldsValue(fieldNames?: Array<string>): { [field: string]: any };
/** 获取一个输入控件的值 */
@ -147,26 +147,26 @@ export type WrappedFormUtils = {
validateFields(
fieldNames: Array<string>,
options: ValidateFieldsOptions,
callback: ValidateCallback,
callback: ValidateCallback<V>,
): void;
validateFields(options: ValidateFieldsOptions, callback: ValidateCallback): void;
validateFields(fieldNames: Array<string>, callback: ValidateCallback): void;
validateFields(options: ValidateFieldsOptions, callback: ValidateCallback<V>): void;
validateFields(fieldNames: Array<string>, callback: ValidateCallback<V>): void;
validateFields(fieldNames: Array<string>, options: ValidateFieldsOptions): void;
validateFields(fieldNames: Array<string>): void;
validateFields(callback: ValidateCallback): void;
validateFields(callback: ValidateCallback<V>): void;
validateFields(options: ValidateFieldsOptions): void;
validateFields(): void;
/** 与 `validateFields` 相似,但校验完后,如果校验不通过的菜单域不在可见范围内,则自动滚动进可见范围 */
validateFieldsAndScroll(
fieldNames: Array<string>,
options: ValidateFieldsOptions,
callback: ValidateCallback,
callback: ValidateCallback<V>,
): void;
validateFieldsAndScroll(options: ValidateFieldsOptions, callback: ValidateCallback): void;
validateFieldsAndScroll(fieldNames: Array<string>, callback: ValidateCallback): void;
validateFieldsAndScroll(options: ValidateFieldsOptions, callback: ValidateCallback<V>): void;
validateFieldsAndScroll(fieldNames: Array<string>, callback: ValidateCallback<V>): void;
validateFieldsAndScroll(fieldNames: Array<string>, options: ValidateFieldsOptions): void;
validateFieldsAndScroll(fieldNames: Array<string>): void;
validateFieldsAndScroll(callback: ValidateCallback): void;
validateFieldsAndScroll(callback: ValidateCallback<V>): void;
validateFieldsAndScroll(options: ValidateFieldsOptions): void;
validateFieldsAndScroll(): void;
/** 获取某个输入控件的 Error */
@ -185,8 +185,8 @@ export type WrappedFormUtils = {
): (node: React.ReactNode) => React.ReactNode;
};
export interface FormComponentProps {
form: WrappedFormUtils;
export interface FormComponentProps<V = any> {
form: WrappedFormUtils<V>;
}
export interface RcBaseFormProps {