/** * 增强类型系统 - 提供更好的类型推断 */ import type { ColumnConfig, ColumnType } from '../components/SmartTable/types' /** * 提取行数据的类型 */ export type ExtractRowType = T extends ColumnConfig ? R : never /** * 根据列配置提取表格数据类型 */ export type TableDataFromColumns = T extends (infer C)[] ? C extends ColumnConfig ? R : any : any /** * 渲染器 Props 类型推断 */ export type InferRendererProps = T extends 'html' ? { style?: string; class?: string; [key: string]: any } : T extends 'copy' ? { successText?: string; errorText?: string; iconColor?: string; [key: string]: any } : T extends 'img' ? { width?: string | number; height?: string | number; fit?: string; previewSrcList?: string[]; [key: string]: any } : T extends 'dict' ? { options: Array<{ label: string; value: string | number; listClass?: string; cssClass?: string }>; showValue?: boolean } : T extends 'map' ? { options: Record } : T extends 'input' ? { placeholder?: string; size?: 'small' | 'default' | 'large'; clearable?: boolean } : T extends 'select' ? { options: Array<{ label: string; value: string | number }>; placeholder?: string; clearable?: boolean } : { [key: string]: any } /** * 快捷创建列的辅助函数(类型安全简化版) */ export function defineColumn( key: string, config?: Partial> ): ColumnConfig { return { key, ...config } as ColumnConfig }