From 4ad6a55474ce08d8dff0f91232d8d2e9ea0705ee Mon Sep 17 00:00:00 2001 From: mumiao Date: Sat, 27 Feb 2021 23:51:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20form.item=20is=20not=20type=20safe=20due?= =?UTF-8?q?=20to=20not=20forwarding=20their=20type=20para=E2=80=A6=20(#293?= =?UTF-8?q?97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: form.item is not type safe due to not forwarding their type parameters to the rcForm components * test: add test cases --- components/form/FormItem.tsx | 4 ++-- components/form/__tests__/type.test.tsx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index b22dee3934..241e1fe025 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -26,7 +26,7 @@ const ValidateStatuses = tuple('success', 'warning', 'error', 'validating', ''); export type ValidateStatus = typeof ValidateStatuses[number]; type RenderChildren = (form: FormInstance) => React.ReactNode; -type RcFieldProps = Omit; +type RcFieldProps = Omit, 'children'>; type ChildrenType = RenderChildren | React.ReactNode; interface MemoInputProps { @@ -43,7 +43,7 @@ const MemoInput = React.memo( export interface FormItemProps extends FormItemLabelProps, FormItemInputProps, - RcFieldProps { + RcFieldProps { prefixCls?: string; noStyle?: boolean; style?: React.CSSProperties; diff --git a/components/form/__tests__/type.test.tsx b/components/form/__tests__/type.test.tsx index 5f79e28cee..3ea4303f3d 100644 --- a/components/form/__tests__/type.test.tsx +++ b/components/form/__tests__/type.test.tsx @@ -73,8 +73,10 @@ describe('Form.typescript', () => { > > {({ getFieldsValue }) => { - const values: FormValues = getFieldsValue(); + const values = getFieldsValue(); expect(values).toBeTruthy(); + expect(values.username).toBeTruthy(); + expect(values.path1?.path2).toBeTruthy(); return null; }}