bevacqua / react-dragula

:ok_hand: Drag and drop so simple it hurts
http://bevacqua.github.io/react-dragula
MIT License
994 stars 77 forks source link

How to use it in `typescript`? #33

Open zhaoyi0113 opened 5 years ago

zhaoyi0113 commented 5 years ago

I get an error Could not find a declaration file for module 'react-dragula' when using react-dragula in typescript. Where can I find the type definition for this component?

AntiMoron commented 5 years ago

Would you support typescript if it's possible? @bevacqua

AdrianMrn commented 4 years ago

Simply create an index.d.ts file and add these lines:

declare module 'react-dragula' {
    export default function(
        containers: Array<HTMLElement>,
        options: import('dragula').DragulaOptions
    ): import('dragula').Drake;
}

and run yarn add @types/dragula --dev or npm install @types/dragula --save-dev

JoshMcCullough commented 4 years ago

It'd be great if this was just included in the package!

AdrianMrn commented 4 years ago

@JoshMcCullough your comment gave me the idea to add the type definition to the DefinitelyTyped repository. My PR just got merged: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46828#event-3678017351

So now you can just run yarn add @types/react-dragula or npm install @types/react-dragula --save, and it should work 🎉

JoshMcCullough commented 4 years ago

@AdrianMrn Great, thanks!