Browse Source

chore(components): improve ts types for Table's updateTableData

main
刘凯 1 year ago
parent
commit
46cd8755d2
  1. 2
      src/components/Form/src/props.ts
  2. 3
      src/components/Table/src/hooks/useTable.ts
  3. 3
      src/components/Table/src/types/table.ts

2
src/components/Form/src/props.ts

@ -90,7 +90,7 @@ export const basicProps = {
layout: propTypes.oneOf(['horizontal', 'vertical', 'inline']).def('horizontal'), layout: propTypes.oneOf(['horizontal', 'vertical', 'inline']).def('horizontal'),
tableAction: { tableAction: {
type: Object as PropType<TableActionType>, type: Object as PropType<TableActionType<any>>,
}, },
wrapperCol: Object as PropType<Partial<ColEx>>, wrapperCol: Object as PropType<Partial<ColEx>>,

3
src/components/Table/src/hooks/useTable.ts

@ -124,7 +124,8 @@ export function useTable<T>(tableProps?: Props<T>): [
getSize: () => { getSize: () => {
return toRaw(getTableInstance().getSize()) return toRaw(getTableInstance().getSize())
}, },
updateTableData: <K extends keyof T>(index: number, key: K, value: T[K]) => { // eslint-disable-next-line ts/ban-types
updateTableData: <K extends keyof T | (string & {})>(index: number, key: K, value: K extends keyof T ? T[K] : any) => {
return getTableInstance().updateTableData(index, key, value) return getTableInstance().updateTableData(index, key, value)
}, },
deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => { deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => {

3
src/components/Table/src/types/table.ts

@ -115,7 +115,8 @@ export interface TableActionType<T = Recordable> {
getRowSelection: () => TableRowSelection<EditRecordRow<T>> getRowSelection: () => TableRowSelection<EditRecordRow<T>>
getCacheColumns: () => BasicColumn[] getCacheColumns: () => BasicColumn[]
emit?: EmitType emit?: EmitType
updateTableData: <K extends keyof T>(index: number, key: K, value: T[K]) => Promise<EditRecordRow<T>> // eslint-disable-next-line ts/ban-types
updateTableData: <K extends keyof T | (string & {})>(index: number, key: K, value: K extends keyof T ? T[K] : any) => Promise<EditRecordRow<T>>
setShowPagination: (show: boolean) => Promise<void> setShowPagination: (show: boolean) => Promise<void>
getShowPagination: () => boolean getShowPagination: () => boolean
setCacheColumnsByField?: (dataIndex: string | undefined, value: BasicColumn) => void setCacheColumnsByField?: (dataIndex: string | undefined, value: BasicColumn) => void