isSortable type guards use "any" in return type
- Dominant language
- TypeScript
- Stars
- 17.6k
- Forks
- 924
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
I'm working in a build environment that's fairly strict about our use of `any`.
I've found that the `isSortable()` type guard isn't very helpful in that environment because all it guarantees is `SortableDraggable` | `SortableDroppable`. We need something that can return `SortableDraggable | SortableDroppable` where `T` is a known subtype of `Data`.
For now, I've created alternate versions of `isSortable()` and `isSortableOperation()` that do this. I'm wondering if you'd consider integrating our changes into dnd-kit?
```ts
import { Data, Draggable, DragOperation, Droppable } from "@dnd-kit/abstract";
import { SortableDraggable, SortableDroppable } from "@dnd-kit/dom/sortable";
export function isSortable(
element: Draggable | null,
): element is SortableDraggable;
export function isSortable(
element: Droppable | null,
): element is SortableDroppable;
export function isSortable(
element: Draggable | Droppable | null,
): element is SortableDroppable | SortableDraggable {
return element instanceof SortableDroppable || element instanceof SortableDraggable;
}
export function isSortableOperation(
operation: DragOperation, Droppable>,
): operation is DragOperation, SortableDroppable> {
return isSortable(operation.source) && isSortable(operation.target);
}
```
Contributor guide
Research direction
Start at the TypeScript definitions of isSortable() and isSortableOperation(), using the shown Data, Draggable, Droppable, and DragOperation types to trace their current guards. Verify that a known T is preserved in both return types and that the package’s existing type checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100