Skip to content

Commit 2d3509e

Browse files
committed
✨ fix(sortable-list): improve generic type support for SortableList
1 parent 086bf8a commit 2d3509e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/SortableList/SortableList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import DragHandle from './components/DragHandle';
2323
import SortableItem from './components/SortableItem';
2424
import SortableOverlay from './components/SortableOverlay';
2525
import { styles } from './style';
26-
import { type SortableListProps } from './type';
26+
import { type SortableListItem, type SortableListProps } from './type';
2727

2828
const SortableListParent = memo<SortableListProps>(
2929
({ ref, items, onChange, renderItem, gap = 8, ...rest }) => {
@@ -72,7 +72,7 @@ const SortableListParent = memo<SortableListProps>(
7272
SortableListParent.displayName = 'SortableList';
7373

7474
export interface ISortableList {
75-
(props: SortableListProps): ReactNode;
75+
<T extends SortableListItem = SortableListItem>(props: SortableListProps<T>): ReactNode;
7676
DragHandle: typeof DragHandle;
7777
Item: typeof SortableItem;
7878
}

src/SortableList/type.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ export interface SortableListItem {
66
[key: string]: any;
77
id: string | number;
88
}
9-
export interface SortableListProps extends Omit<FlexboxProps, 'onChange'> {
10-
items: SortableListItem[];
11-
onChange: (items: SortableListItem[]) => void;
9+
export interface SortableListProps<T extends SortableListItem = SortableListItem> extends Omit<
10+
FlexboxProps,
11+
'onChange'
12+
> {
13+
items: T[];
14+
onChange: (items: T[]) => void;
1215
ref?: Ref<HTMLUListElement>;
13-
renderItem: (item: SortableListItem) => ReactNode;
16+
renderItem: (item: T) => ReactNode;
1417
}

0 commit comments

Comments
 (0)