Skip to content

Commit

Permalink
Add generic type to form values
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Mar 12, 2019
1 parent 97880a9 commit d1f64b1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions components/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' */
Expand Down Expand Up @@ -134,7 +134,7 @@ export type ValidateFieldsOptions = {
};

// function create
export type WrappedFormUtils = {
export type WrappedFormUtils<V = any> = {
/** 获取一组输入控件的值,如不传入参数,则获取全部组件的值 */
getFieldsValue(fieldNames?: Array<string>): { [field: string]: any };
/** 获取一个输入控件的值 */
Expand All @@ -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 */
Expand All @@ -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 {
Expand Down

0 comments on commit d1f64b1

Please sign in to comment.