Shopify / draggable

The JavaScript Drag & Drop library your grandparents warned you about.
https://shopify.github.io/draggable
MIT License
18k stars 1.09k forks source link

Typescript: Unable to use Sensors in Droppable #498

Open Git-Hub-User-0 opened 3 years ago

Git-Hub-User-0 commented 3 years ago

Hi I am getting while adding Sensors to Droppable(using Typescript):

import { Droppable, Sensors, DragSensor } from "@shopify/draggable";
const droppable = new Droppable(document.querySelectorAll(".app"), {
      draggable: ".item",
      dropzone: ".dropzone",
      sensors: [Sensors.DragSensor] || [DragSensor]
    });

Error: 'Sensors' only refers to a type, but is being used as a value here

If i try to add DragSensor directly, then i getting following error: Type 'typeof DragSensor' is missing the following properties from type 'Sensor': attach, detach, addContainer, removeContainer, trigger

"@shopify/draggable": "^1.0.0-beta.12"

Please help with this. Thanks in advance.

@zjffun

zjffun commented 3 years ago

Thank you for your bug report.

I can't find a temporary way to fix class type define. It seems that it can only be temporarily fixed by setting the any type now.

import { Droppable, DragSensor } from "@shopify/draggable";

const droppable = new Droppable(document.querySelectorAll(".app"), {
  draggable: ".item",
  dropzone: ".dropzone",
  sensors: [DragSensor as any],
});

I will create a PR to fix it.