From 95ecb2a2eb9644b3a49e4fc9c783422396f72864 Mon Sep 17 00:00:00 2001 From: lnuxe <144079529+lnuxe@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:35:57 +0800 Subject: [PATCH] fix(form): narrow FormValidateResult boolean branch to true Fixes #1021 --- db/TDesign.db | Bin 1175552 -> 1175552 bytes .../packages/components/form/README.en-US.md | 4 ++-- .../packages/components/form/README.md | 4 ++-- .../packages/components/form/type.ts | 2 +- .../uniapp-components/form/README.en-US.md | 4 ++-- .../packages/uniapp-components/form/README.md | 4 ++-- .../packages/uniapp-components/form/type.ts | 2 +- .../src/form/form.en-US.md | 2 +- .../tdesign-mobile-react/src/form/form.md | 2 +- .../tdesign-mobile-react/src/form/type.ts | 2 +- .../tdesign-mobile-vue/src/form/form.en-US.md | 4 ++-- .../tdesign-mobile-vue/src/form/form.md | 4 ++-- .../tdesign-mobile-vue/src/form/type.ts | 2 +- .../packages/components/form/form.en-US.md | 2 +- .../packages/components/form/form.md | 2 +- .../packages/components/form/type.ts | 2 +- .../packages/components/form/form.en-US.md | 4 ++-- .../packages/components/form/form.md | 4 ++-- .../packages/components/form/type.ts | 2 +- .../tdesign-vue/src/form/form.en-US.md | 4 ++-- .../products/tdesign-vue/src/form/form.md | 4 ++-- .../products/tdesign-vue/src/form/type.ts | 2 +- packages/scripts/api.json | 10 +++++----- 23 files changed, 36 insertions(+), 36 deletions(-) diff --git a/db/TDesign.db b/db/TDesign.db index 0170fd4cc92dcd9a726a708659b86a5d0665b0bc..19d6f727fb41cde3b162c52e5eaa272ffaaeaee2 100644 GIT binary patch delta 276 zcmZp8;NI}SeS$Qj_e2?IR&NHq-X9xN7S}VfZsur6<`T3olxAWQWt8OL0tZGhIUiT_ZyULsKhbBOqd6U})CwZ`bc<+^*lxbbWz@2m^l! z-z=VAJT2UZxRe-0IEvWY*cI8jCM!PpCf-%lAtM8_Ko)30w>$%9v!k(b8|!urL*~oO z0_bK>|M!Dgb-IBmvm(p^MvU!UX3Rj$0>rF9%m&2lK+FNeoIuP4#N0s41H`;Q%m>8$ W+q=vJF5c%ubvW4Y?R{c`MK=N21ydOS delta 274 zcmZp8;NI}SeS$Qj$3z)tRu2ZfHqDJGi|ZMgHghy2a|t>XN;5HuGD>pr^0pT`p?*@$uSjJ_5DBV7YCT|+|!Ljx;QODj{8X8rzl{eH&n`u$AT z7f1*)@R#t-;`znX!hMKKiBXWFh`o(nk*#aGq5<<4vC&y?8>=74sf1Av$Xh*^P{4T#x+m;;D8ftU-3xq+Am oh)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface SubmitContext { e?: FormSubmitEvent; validateResult: FormValidateResult; firstError?: string; fields?: any }`

`type FormValidateResult = boolean \| ValidateResultObj`

`type ValidateResultObj = { [key in keyof T]: boolean \| ValidateResultList }`

`type ValidateResultList = Array`

`type AllValidateResult = CustomValidateObj \| ValidateResultType`

`interface ValidateResultType extends FormRule { result: boolean }`

`type ValidateResult = { [key in keyof T]: boolean \| ErrorList }`

`type ErrorList = Array`
+submit | `(detail: SubmitContext)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface SubmitContext { e?: FormSubmitEvent; validateResult: FormValidateResult; firstError?: string; fields?: any }`

`type FormValidateResult = true \| ValidateResultObj`

`type ValidateResultObj = { [key in keyof T]: boolean \| ValidateResultList }`

`type ValidateResultList = Array`

`type AllValidateResult = CustomValidateObj \| ValidateResultType`

`interface ValidateResultType extends FormRule { result: boolean }`

`type ValidateResult = { [key in keyof T]: boolean \| ErrorList }`

`type ErrorList = Array`
validate | `(result: ValidateResultContext)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`type ValidateResultContext = Omit, 'e'>`
### FormInstanceFunctions 组件实例方法 @@ -38,7 +38,7 @@ clear-validate | `(fields?: Array)` | \- | required reset | `(params?: FormResetParams)` | \- | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface FormResetParams { type?: 'initial' \| 'empty'; fields?: Array }`
set-validate-message | `(message: FormValidateMessage)` | \- | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`type FormValidateMessage = { [field in keyof FormData]: FormItemValidateMessage[] }`

`interface FormItemValidateMessage { type: 'warning' \| 'error'; message: string }`
submit | `(params?: { showErrorMessage?: boolean })` | \- | required -validate | `(params?: FormValidateParams)` | `Promise> ` | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface FormValidateParams { fields?: Array; showErrorMessage?: boolean; trigger?: ValidateTriggerType }`

`type ValidateTriggerType = 'blur' \| 'change' \| 'submit' \| 'all'`

`type FormValidateResult = boolean \| ValidateResultObj`

`type ValidateResultObj = { [key in keyof T]: boolean \| ValidateResultList }`

`type ValidateResultList = Array`

`type AllValidateResult = CustomValidateObj \| ValidateResultType`

`interface ValidateResultType extends FormRule { result: boolean }`
+validate | `(params?: FormValidateParams)` | `Promise> ` | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface FormValidateParams { fields?: Array; showErrorMessage?: boolean; trigger?: ValidateTriggerType }`

`type ValidateTriggerType = 'blur' \| 'change' \| 'submit' \| 'all'`

`type FormValidateResult = true \| ValidateResultObj`

`type ValidateResultObj = { [key in keyof T]: boolean \| ValidateResultList }`

`type ValidateResultList = Array`

`type AllValidateResult = CustomValidateObj \| ValidateResultType`

`interface ValidateResultType extends FormRule { result: boolean }`
### FormItem Props diff --git a/packages/products/tdesign-miniprogram/packages/components/form/README.md b/packages/products/tdesign-miniprogram/packages/components/form/README.md index 96c8ca966..3e183a181 100644 --- a/packages/products/tdesign-miniprogram/packages/components/form/README.md +++ b/packages/products/tdesign-miniprogram/packages/components/form/README.md @@ -27,7 +27,7 @@ submit-with-warning-message | Boolean | false | 【讨论中】当校验结果 名称 | 参数 | 描述 -- | -- | -- reset | `(detail: { e?: FormResetEvent })` | 表单重置时触发。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) -submit | `(detail: SubmitContext)` | 表单提交时触发。其中 `context.validateResult` 表示校验结果,`context.firstError` 表示校验不通过的第一个规则提醒。`context.validateResult` 值为 `true` 表示校验通过;如果校验不通过,`context.validateResult` 值为校验结果列表。
【注意】⚠️ 默认情况,输入框按下 Enter 键会自动触发提交事件,如果希望禁用这个默认行为,可以给输入框添加 enter 事件,并在事件中设置 `e.preventDefault()`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface SubmitContext { e?: FormSubmitEvent; validateResult: FormValidateResult; firstError?: string; fields?: any }`

`type FormValidateResult = boolean \| ValidateResultObj`

`type ValidateResultObj = { [key in keyof T]: boolean \| ValidateResultList }`

`type ValidateResultList = Array`

`type AllValidateResult = CustomValidateObj \| ValidateResultType`

`interface ValidateResultType extends FormRule { result: boolean }`

`type ValidateResult = { [key in keyof T]: boolean \| ErrorList }`

`type ErrorList = Array`
+submit | `(detail: SubmitContext)` | 表单提交时触发。其中 `context.validateResult` 表示校验结果,`context.firstError` 表示校验不通过的第一个规则提醒。`context.validateResult` 值为 `true` 表示校验通过;如果校验不通过,`context.validateResult` 值为校验结果列表。
【注意】⚠️ 默认情况,输入框按下 Enter 键会自动触发提交事件,如果希望禁用这个默认行为,可以给输入框添加 enter 事件,并在事件中设置 `e.preventDefault()`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`interface SubmitContext { e?: FormSubmitEvent; validateResult: FormValidateResult; firstError?: string; fields?: any }`

`type FormValidateResult = true \| ValidateResultObj`

`type ValidateResultObj = { [key in keyof T]: boolean \| ValidateResultList }`

`type ValidateResultList = Array`

`type AllValidateResult = CustomValidateObj \| ValidateResultType`

`interface ValidateResultType extends FormRule { result: boolean }`

`type ValidateResult = { [key in keyof T]: boolean \| ErrorList }`

`type ErrorList = Array`
validate | `(result: ValidateResultContext)` | 校验结束后触发,result 值为 true 表示校验通过;如果校验不通过,result 值为校验结果列表。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。
`type ValidateResultContext = Omit, 'e'>`
### FormInstanceFunctions 组件实例方法 @@ -38,7 +38,7 @@ clear-validate | `(fields?: Array)` | \- | 必需。清空校验 reset | `(params?: FormResetParams)` | \- | 必需。重置表单,表单里面没有重置按钮`