fix: form.item is not type safe due to not forwarding their type para… (#29397)

* fix: form.item is not type safe due to not forwarding their type parameters to the rcForm components

* test: add test cases
This commit is contained in:
mumiao 2021-02-27 23:51:35 +08:00 committed by GitHub
parent 52bbca4047
commit 4ad6a55474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -26,7 +26,7 @@ const ValidateStatuses = tuple('success', 'warning', 'error', 'validating', '');
export type ValidateStatus = typeof ValidateStatuses[number]; export type ValidateStatus = typeof ValidateStatuses[number];
type RenderChildren<Values = any> = (form: FormInstance<Values>) => React.ReactNode; type RenderChildren<Values = any> = (form: FormInstance<Values>) => React.ReactNode;
type RcFieldProps = Omit<FieldProps, 'children'>; type RcFieldProps<Values = any> = Omit<FieldProps<Values>, 'children'>;
type ChildrenType<Values = any> = RenderChildren<Values> | React.ReactNode; type ChildrenType<Values = any> = RenderChildren<Values> | React.ReactNode;
interface MemoInputProps { interface MemoInputProps {
@ -43,7 +43,7 @@ const MemoInput = React.memo(
export interface FormItemProps<Values = any> export interface FormItemProps<Values = any>
extends FormItemLabelProps, extends FormItemLabelProps,
FormItemInputProps, FormItemInputProps,
RcFieldProps { RcFieldProps<Values> {
prefixCls?: string; prefixCls?: string;
noStyle?: boolean; noStyle?: boolean;
style?: React.CSSProperties; style?: React.CSSProperties;

View File

@ -73,8 +73,10 @@ describe('Form.typescript', () => {
<Form<FormValues>> <Form<FormValues>>
<Form.Item<FormValues>> <Form.Item<FormValues>>
{({ getFieldsValue }) => { {({ getFieldsValue }) => {
const values: FormValues = getFieldsValue(); const values = getFieldsValue();
expect(values).toBeTruthy(); expect(values).toBeTruthy();
expect(values.username).toBeTruthy();
expect(values.path1?.path2).toBeTruthy();
return null; return null;
}} }}
</Form.Item> </Form.Item>