ng2-dragula icon indicating copy to clipboard operation
ng2-dragula copied to clipboard

[usage question] DragulaOptions

Open tcarlsen opened this issue 7 years ago • 9 comments

Use case description (required) What to use DragulaOptions

Additional context

Following the README

    dragulaService.createGroup("VAMPIRES", {
      removeOnSpill: true
    });

I get the following error:

error TS2345: Argument of type '{ removeOnSpill: boolean; }' is not assignable to parameter of type 'DragulaOptions<any>'.
  Object literal may only specify known properties, and 'removeOnSpill' does not exist in type 'DragulaOptions<any>'.

tcarlsen avatar Sep 10 '18 11:09 tcarlsen

You don’t have @types/dragula’. Get the latest version of Ng2-Dragula, and it will be installed. If that’s not it, I can’t help you.

cormacrelf avatar Sep 10 '18 11:09 cormacrelf

https://github.com/valor-software/ng2-dragula/blob/master/modules/ng2-dragula/src/DragulaOptions.ts

cormacrelf avatar Sep 10 '18 11:09 cormacrelf

I do have that installed. I did upgrade from 1.5 to 2.1

Just tried to remove my whole node_modules folder and reinstall everything.. Still gets same error

tcarlsen avatar Sep 10 '18 11:09 tcarlsen

Maybe a typescript upgrade is in order

cormacrelf avatar Sep 10 '18 22:09 cormacrelf

Also probably some typeRoots settings in your tsconfig

Basically, this stuff works in new Angular apps, so there’s something wrong with the way your types/dragula is being resolved or installed.

cormacrelf avatar Sep 10 '18 22:09 cormacrelf

I have same error. Everything working as expected, but this error popup in the terminal. I also moved from 1.5 to 2.1.

error TS2345: Argument of type '{ moves: (el: any, container: any, handle: any) => boolean; }' is not assignable to parameter of type 'DragulaOptions<any>'.
  Object literal may only specify known properties, and 'moves' does not exist in type 'DragulaOptions<any>'.

CrackerakiUA avatar Sep 13 '18 10:09 CrackerakiUA

Can you import directly from @types/dragula? i.e.

import { DragulaOptions } from 'dragula';
const x: DragulaOptions = {
    moves: () => true,
};

As I posted above, ng2-dragula depends directly on those type defs, and the DragulaOptions<T> exported by this library just extend the originals, so all properties from @types/dragula are available. Unless your typescript isn't picking up the appropriate * => @types/* implicit mapping through the typeRoots compiler option.

cormacrelf avatar Sep 13 '18 11:09 cormacrelf

Works for me, thanks

CrackerakiUA avatar Sep 14 '18 06:09 CrackerakiUA

OK, after a few lost hours, I managed to have it working thanks to @cormacrelf : `

import { DragulaService } from '../../../../node_modules/ng2-dragula'; import { DragulaOptions } from 'dragula'; ... constructor(

    ...,

    private dragulaService: DragulaService) {

        let options: DragulaOptions = {
            moves: (el, source, handle) => handle.className.includes('drag-handle')
        }

        this.dragulaService.createGroup("steps-bag", options);
}`

mythcyrax avatar May 03 '19 07:05 mythcyrax

Thank you @mythcyrax for sharing this solution, works great

thomae82 avatar Feb 28 '23 08:02 thomae82

I just did an npm install @types/ng2-dragula@latest and that did the trick. Or so I thought. It just got me into another set of failures.

jkyoutsey avatar May 09 '23 21:05 jkyoutsey