Skip to content

Commit f1898de

Browse files
committed
chore: Fix Field missing ts generic
1 parent 96ffb2c commit f1898de

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

examples/basic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class Demo extends React.Component {
5252
<button type="submit">Submit</button>
5353

5454
<h4>Show additional field when `username` is `111`</h4>
55-
<Field dependencies={['username']}>
55+
<Field<FormValues> dependencies={['username']}>
5656
{(control, meta, context) => {
5757
const { username } = context.getFieldsValue(true);
5858
console.log('my render!', username);

src/Field.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ interface ChildProps {
4949
[name: string]: any;
5050
}
5151

52-
export interface InternalFieldProps {
52+
export interface InternalFieldProps<Values = any> {
5353
children?:
5454
| React.ReactElement
55-
| ((control: ChildProps, meta: Meta, form: FormInstance) => React.ReactNode);
55+
| ((control: ChildProps, meta: Meta, form: FormInstance<Values>) => React.ReactNode);
5656
/**
5757
* Set up `dependencies` field.
5858
* When dependencies field update and current field is touched,
@@ -78,7 +78,7 @@ export interface InternalFieldProps {
7878
isListField?: boolean;
7979
}
8080

81-
export interface FieldProps extends Omit<InternalFieldProps, 'name'> {
81+
export interface FieldProps<Values = any> extends Omit<InternalFieldProps<Values>, 'name'> {
8282
name?: NamePath;
8383
}
8484

@@ -498,7 +498,7 @@ class Field extends React.Component<InternalFieldProps, FieldState, InternalForm
498498
}
499499
}
500500

501-
const WrapperField: React.FC<FieldProps> = ({ name, ...restProps }) => {
501+
function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>) {
502502
const namePath = name !== undefined ? getNamePath(name) : undefined;
503503

504504
let key: string = 'keep';
@@ -514,6 +514,6 @@ const WrapperField: React.FC<FieldProps> = ({ name, ...restProps }) => {
514514
}
515515

516516
return <Field key={key} name={namePath} {...restProps} />;
517-
};
517+
}
518518

519519
export default WrapperField;

src/interface.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ type RecursivePartial<T> = T extends object
197197
export interface FormInstance<Values = any> {
198198
// Origin Form API
199199
getFieldValue: (name: NamePath) => StoreValue;
200-
getFieldsValue: (
201-
nameList?: NamePath[] | true,
202-
filterFunc?: (meta: Meta) => boolean,
203-
) => Values | any;
200+
getFieldsValue(): Values;
201+
getFieldsValue(nameList: NamePath[] | true, filterFunc?: (meta: Meta) => boolean): any;
204202
getFieldError: (name: NamePath) => string[];
205203
getFieldsError: (nameList?: NamePath[]) => FieldError[];
206204
isFieldsTouched(nameList?: NamePath[], allFieldsTouched?: boolean): boolean;

0 commit comments

Comments
 (0)