Skip to content

Commit 2f6e5e5

Browse files
committed
fix: trigger type in Rule
1 parent 3edbf23 commit 2f6e5e5

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alifd/field",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Fields can be used to manage data when it comes to form data manipulation and validation. After being associated with a component, the form data can be automatically written back, read, and verified.",
55
"files": [
66
"demo/",
@@ -93,7 +93,7 @@
9393
"表单"
9494
]
9595
},
96-
"homepage": "https://unpkg.com/@alifd/field@2.0.2/build/index.html",
96+
"homepage": "https://unpkg.com/@alifd/field@2.0.3/build/index.html",
9797
"bugs": "https://github.com/alibaba-fusion/field/issues",
9898
"publishConfig": {
9999
"access": "public",

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Field {
248248
: field.value,
249249
};
250250

251-
let rulesMap: Record<string, Omit<Rule, 'trigger'>[]> = {};
251+
let rulesMap: Record<string, Rule[]> = {};
252252

253253
if (this.options.autoValidate && autoValidate !== false) {
254254
// trigger map in rules,
@@ -1165,7 +1165,7 @@ class Field {
11651165
}
11661166
}
11671167

1168-
_validate(name: string, rule: Omit<Rule, 'trigger'>[], trigger: string) {
1168+
_validate(name: string, rule: Rule[], trigger: string) {
11691169
const field = this._get(name);
11701170
if (!field) {
11711171
return;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export type Rule = {
130130
/**
131131
* 触发校验的事件名称
132132
*/
133-
trigger?: 'onChange' | 'onBlur' | string;
133+
trigger?: string | string[];
134134
};
135135

136136
export type InitOption<

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export function getValueFromEvent(e: unknown) {
245245
}
246246

247247
function validateMap<Rule extends { trigger?: string | string[]; [key: string]: unknown }>(
248-
rulesMap: Record<string, Omit<Rule, 'trigger'>[]>,
248+
rulesMap: Record<string, Rule[]>,
249249
rule: Rule,
250250
defaultTrigger: string
251251
) {
@@ -281,7 +281,7 @@ export function mapValidateRules<Rule extends { [key: string]: unknown; trigger?
281281
rules: Rule[],
282282
defaultTrigger: string
283283
) {
284-
const rulesMap: Record<string, Array<Omit<Rule, 'trigger'>>> = {};
284+
const rulesMap: Record<string, Array<Rule>> = {};
285285

286286
rules.forEach((rule) => {
287287
validateMap(rulesMap, rule, defaultTrigger);

0 commit comments

Comments
 (0)