Skip to content

Commit

Permalink
style(form): 完善filterFunction类型定义
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Nov 21, 2023
1 parent ab02c2f commit ad008b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions packages/form/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ export interface FormItem {
/** 字段名 */
name?: string | number;
/** 额外的提示信息,和 help 类似,当提示文案同时出现时,可以使用这个。 */
extra?: string | FilterFunction;
extra?: string | FilterFunction<string>;
/** 配置提示信息 */
tooltip?: string | FilterFunction;
tooltip?: string | FilterFunction<string>;
/** 是否置灰 */
disabled?: boolean | FilterFunction;
/** 使用表单中的值作为key,例如配置了text,则使用model.text作为key */
key?: string;
/** 是否显示 */
display?: boolean | 'expand' | FilterFunction;
display?: boolean | 'expand' | FilterFunction<boolean | 'expand'>;
/** 值发生改变时调用的方法 */
onChange?: OnChangeHandler;
/** label 标签的文本 */
text?: string | FilterFunction;
text?: string | FilterFunction<string>;
/** 右侧感叹号 */
tip?: string;

Expand Down Expand Up @@ -158,7 +158,7 @@ export type TypeFunction = (
},
) => string;

export type FilterFunction = (
export type FilterFunction<T = boolean> = (
mForm: FormState | undefined,
data: {
model: Record<any, any>;
Expand All @@ -168,7 +168,7 @@ export type FilterFunction = (
prop: string;
config: any;
},
) => boolean;
) => T;

type OnChangeHandler = (
mForm: FormState | undefined,
Expand Down Expand Up @@ -667,7 +667,7 @@ export interface TableConfig extends FormItem {
/** 是否显示全屏按钮 */
enableFullscreen?: boolean;
fixed?: boolean;
itemExtra?: string | FilterFunction;
itemExtra?: string | FilterFunction<string>;
rowKey?: string;
}

Expand All @@ -680,8 +680,8 @@ export interface GroupListConfig extends FormItem {
tableItems?: FormConfig;
titleKey?: string;
titlePrefix?: string;
title?: string | FilterFunction;
itemExtra?: string | FilterFunction;
title?: string | FilterFunction<string>;
itemExtra?: string | FilterFunction<string>;
expandAll?: boolean;
addable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
defaultAdd?: (mForm: FormState | undefined, data: any) => any;
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/utils/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const getDefaultValue = function (mForm: FormState | undefined, { defaultValue,
return '';
};

export const filterFunction = (mForm: FormState | undefined, config: any, props: any) => {
export const filterFunction = <T = any>(mForm: FormState | undefined, config: T, props: any) => {
if (typeof config !== 'function') {
return config;
}
Expand Down

0 comments on commit ad008b6

Please sign in to comment.