Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript @types issue #37

Open
hovorun opened this issue Apr 14, 2022 · 5 comments
Open

typescript @types issue #37

hovorun opened this issue Apr 14, 2022 · 5 comments

Comments

@hovorun
Copy link

hovorun commented Apr 14, 2022

When installing the library in my Vue application, I get the next error Cannot resolve definitions for module 'vue-dndrop' seems like it's missing types declaration, can it be solved somehow? Thanks in advance

@amendx
Copy link
Owner

amendx commented Apr 14, 2022

@hovorun can you show me how you're importing the lib? And its component usage?

@xyhxx
Copy link

xyhxx commented May 3, 2022

maybe you can refer to DefinitelyTyped, i hope it can run in typescript

@Lyokolux
Copy link

Lyokolux commented Aug 19, 2022

At the moment:

  • no types are recognized when importing something by vue-dndrop
  • @types/vue-dndrop does not exist

So if you use typescript for your vue project, these package should be treated with an any type. It removes errors but does not provide safety.

I use a stub of it in my env.d.ts:

declare module "vue-dndrop" {
  const Container: any
  const Draggable: any
  export {
    Container,
    Draggable
  }
}

@philiprenich
Copy link

philiprenich commented Oct 26, 2022

@hovorun can you show me how you're importing the lib? And its component usage?

I have the same issue (typescript'd Vue 2 app) and it's a simple module import in my .vue single file component.

...
<script lang="ts">
import { Container } from "vue-dndrop";`
...
</script>
...

Using @Lyokolux removes the errors and allows a build. It would be nice to have TS support, but I understand not everyone wants to do that :)

@cin12211
Copy link

cin12211 commented Feb 4, 2024

Hey you can try this @philiprenich @Lyokolux @amendx @hovorun @xyhxx

declare module 'vue-dndrop' {
  import { type DefineComponent } from 'vue'

  interface DropResult {
    removedIndex: number
    addedIndex: number
    payload: Payload
    element: Element
  }

  interface DragEvent {
    payload: Payload
    isSource: boolean
    willAcceptDrop: boolean
  }

  type Payload = any

  interface NodeDescription {
    value: string
    props: Record<string, any>
  }

  interface DraggableProps {
    dragNotAllowed?: boolean
    tag?: string | NodeDescription
  }

  interface ContainerProps {
    dragStart?: (dragEvent: DragEvent) => void
    dragEnd?: (dragEvent: DragEvent) => void
    dragEnter?: () => void
    dragLeave?: () => void
    dragReady?: (dropResult: DropResult) => void
    drop?: (dropResult: DropResult) => void
    dropNotAllowed?: (dropResult: { payload: any; container: any }) => void

    getChildPayload?: (index: number) => Payload
    shouldAnimateDrop?: (sourceContainerOptions: ContainerProps, payload: Payload) => boolean
    shouldAcceptDrop?: (sourceContainerOptions: ContainerProps, payload: Payload) => boolean
    getGhostParent?: () => Element

    orientation: 'horizontal' | 'vertical'
    behaviour: 'move' | 'copy' | 'drop-zone' | 'contain'
    tag?: string | NodeDescription
    groupName?: string
    lockAxis?: 'x' | 'y'
    dragHandleSelector?: string
    nonDragAreaSelector?: string
    dragBeginDelay?: number
    animationDuration?: number
    autoScrollEnabled?: boolean
    dragClass?: string
    dropClass?: string
    removeOnDropOut?: boolean
    dropPlaceholder?:
      | boolean
      | {
          className: string
          animationDuration: number
          showOnTop: boolean
        }
    fireRelatedEventsOnly?: boolean
  }

  const Draggable: DefineComponent<DraggableProps>

  const Container: DefineComponent<ContainerProps>

  export { Draggable, Container, DropResult, DragEvent }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants