diff --git a/components/_util/withDefaultProps.ts b/components/_util/extendsObject.ts similarity index 53% rename from components/_util/withDefaultProps.ts rename to components/_util/extendsObject.ts index 7ff9a0ae5fe2..80e033c9376b 100644 --- a/components/_util/withDefaultProps.ts +++ b/components/_util/extendsObject.ts @@ -1,8 +1,7 @@ -/* eslint-disable no-redeclare */ -export function mergeProps(a: A, b: B): B & A; -export function mergeProps(a: A, b: B, c: C): C & B & A; -export function mergeProps(...list: any[]) { - const result = { ...list[0] }; +type RecordType = Record; + +function extendsObject(...list: T[]) { + const result: RecordType = { ...list[0] }; for (let i = 1; i < list.length; i++) { const obj = list[i]; @@ -18,3 +17,5 @@ export function mergeProps(...list: any[]) { return result; } + +export default extendsObject; diff --git a/components/list/index.tsx b/components/list/index.tsx index a8858fa2cf71..4b3d579f27c0 100644 --- a/components/list/index.tsx +++ b/components/list/index.tsx @@ -12,7 +12,7 @@ import type { SpinProps } from '../spin'; import Spin from '../spin'; import type { Breakpoint } from '../_util/responsiveObserver'; import { responsiveArray } from '../_util/responsiveObserver'; -import { mergeProps } from '../_util/withDefaultProps'; +import extendsObject from '../_util/extendsObject'; import Item from './Item'; // CSSINJS @@ -191,7 +191,7 @@ function List({ hashId, ); - const paginationProps = mergeProps( + const paginationProps = extendsObject( defaultPaginationProps, { total: dataSource.length, diff --git a/components/table/hooks/usePagination.ts b/components/table/hooks/usePagination.ts index c5ee37c88f38..7e559e4ba928 100644 --- a/components/table/hooks/usePagination.ts +++ b/components/table/hooks/usePagination.ts @@ -1,7 +1,7 @@ import { useState } from 'react'; import type { PaginationProps } from '../../pagination'; import type { TablePaginationConfig } from '../interface'; -import { mergeProps } from '../../_util/withDefaultProps'; +import extendsObject from '../../_util/extendsObject'; export const DEFAULT_PAGE_SIZE = 10; @@ -44,9 +44,13 @@ export default function usePagination( })); // ============ Basic Pagination Config ============ - const mergedPagination = mergeProps(innerPagination, paginationObj, { - total: paginationTotal > 0 ? paginationTotal : total, - }); + const mergedPagination = extendsObject>( + innerPagination, + paginationObj, + { + total: paginationTotal > 0 ? paginationTotal : total, + }, + ); // Reset `current` if data length or pageSize changed const maxPage = Math.ceil((paginationTotal || total) / mergedPagination.pageSize!);