Skip to content

Commit fdbf895

Browse files
Fix types
1 parent a327e46 commit fdbf895

3 files changed

Lines changed: 53 additions & 15 deletions

File tree

addon/components/drag-sort-item.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ interface DragSortItemSignature {
1919
determineForeignPositionAction: unknown;
2020
draggingEnabled: boolean;
2121
dragEndAction?: unknown;
22-
dragStartAction?: unknown;
22+
dragStartAction?: (args: { event: DragEvent; element: HTMLElement; draggedItem: unknown }) => void;
2323
group: string;
24-
handle?: unknown;
25-
index?: number;
26-
isHorizontal?: boolean;
24+
handle?: string;
25+
index: number;
26+
isHorizontal: boolean;
2727
isRtl?: boolean;
2828
item: unknown;
2929
items: Array<unknown>;

addon/components/drag-sort-list.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ interface DragSortListSignature {
99
additionalArgs: unknown;
1010
childClass?: string;
1111
childTagName?: string;
12-
determineForeignPositionAction?: unknown;
12+
determineForeignPositionAction?: (args: { draggedItem: unknown; items: Array<unknown> }) => number;
1313
draggingEnabled: boolean;
1414
dragEndAction?: unknown;
1515
dragStartAction?: unknown;
1616
handle?: unknown;
1717
items: Array<unknown>;
1818
isHorizontal?: boolean;
1919
isRtl?: boolean;
20-
group: unknown;
20+
group: string;
2121
sourceOnly: boolean;
2222
};
2323
}
@@ -175,8 +175,8 @@ export default class DragSortList extends Component<DragSortListSignature> {
175175

176176
let index =
177177
items === sourceList
178-
? items.indexOf(draggedItem) + 1
179-
: determineForeignPositionAction({ draggedItem, items });
178+
? (items as Array<unknown>).indexOf(draggedItem) + 1
179+
: determineForeignPositionAction!({ draggedItem, items });
180180

181181
if (index >= itemsLength) {
182182
index = itemsLength - 1;

addon/services/drag-sort.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ export default class DragSort extends Service.extend(EventedMixin) {
2323
@tracked lastDragEnteredList: unknown | null = null;
2424
@tracked isHorizontal?: boolean;
2525

26-
startDragging({ additionalArgs, item, index, items, group, isHorizontal }) {
26+
startDragging({
27+
additionalArgs,
28+
item,
29+
index,
30+
items,
31+
group,
32+
isHorizontal,
33+
}: {
34+
additionalArgs: unknown;
35+
item: unknown;
36+
index: number;
37+
items: Array<unknown>;
38+
group: string;
39+
isHorizontal: boolean;
40+
}) {
41+
// @ts-expect-error TODO: fix this type error
2742
setProperties(this, {
2843
isDragging: true,
2944
isDraggingUp: false,
@@ -51,7 +66,17 @@ export default class DragSort extends Service.extend(EventedMixin) {
5166
});
5267
}
5368

54-
draggingOver({ group, index, items, isDraggingUp }) {
69+
draggingOver({
70+
group,
71+
index,
72+
items,
73+
isDraggingUp,
74+
}: {
75+
group: string;
76+
index: number;
77+
items: Array<unknown>;
78+
isDraggingUp: boolean;
79+
}) {
5580
// Ignore hovers over irrelevant groups
5681
if (group !== this.group) return;
5782

@@ -81,7 +106,19 @@ export default class DragSort extends Service.extend(EventedMixin) {
81106
});
82107
}
83108

84-
dragEntering({ group, items, isHorizontal, targetArgs, targetIndex = 0 }) {
109+
dragEntering({
110+
group,
111+
items,
112+
isHorizontal,
113+
targetArgs,
114+
targetIndex = 0,
115+
}: {
116+
group: string;
117+
items: Array<unknown>;
118+
isHorizontal?: boolean;
119+
targetArgs: unknown;
120+
targetIndex?: number;
121+
}) {
85122
// Ignore entering irrelevant groups
86123
if (group !== this.group) return;
87124

@@ -106,14 +143,15 @@ export default class DragSort extends Service.extend(EventedMixin) {
106143
}
107144

108145
// Remember entering a new list
146+
// @ts-expect-error TODO: fix this type error
109147
setProperties(this, {
110148
targetList: items,
111149
lastDragEnteredList: items,
112150
isHorizontal: isHorizontal,
113151
});
114152
}
115153

116-
endDragging({ action }) {
154+
endDragging({ action }: { action: unknown }) {
117155
const sourceArgs = this.sourceArgs;
118156
const sourceList = this.sourceList;
119157
const sourceIndex = this.sourceIndex as number;
@@ -133,11 +171,11 @@ export default class DragSort extends Service.extend(EventedMixin) {
133171
// Dragging down
134172
!isDraggingUp &&
135173
// Target index is not after the last item
136-
targetIndex < targetList.get('length') &&
174+
targetIndex < (targetList as any)?.get('length') &&
137175
// The only element in target list is not the one dragged
138176
!(
139-
targetList.get('length') === 1 &&
140-
targetList.get('firstObject') === draggedItem
177+
(targetList as any)?.get('length') === 1 &&
178+
(targetList as any)?.get('firstObject') === draggedItem
141179
)
142180
)
143181
targetIndex++;

0 commit comments

Comments
 (0)