vue-shepherd icon indicating copy to clipboard operation
vue-shepherd copied to clipboard

Would be nice to add type declarations for typescript

Open garyo opened this issue 4 years ago • 10 comments

I got it working by adding a .d.ts containing just declare module vue-shepherd but it would be good to include a more complete type declaration for typescript users.

garyo avatar Dec 09 '20 13:12 garyo

Hi @garyo, I totally agree! We have the types in the main Shepherd repo here https://github.com/shipshapecode/shepherd/tree/master/src/types

Can those be imported and used?

RobbieTheWagner avatar Dec 09 '20 14:12 RobbieTheWagner

I would think so, though you'll still need to add types for the things you add to the Vue prototype. I'm just getting started with vue-shepherd (migrating from vue-tour) and I'm typing my steps using the Shepherd types; that works fine.

garyo avatar Dec 09 '20 14:12 garyo

@garyo I don't think we added anything to this Vue wrapper really. I had plans to add more features, but I've been busy with other things. If you'd like to add imports of the types here and/or other features, we would love the help!

RobbieTheWagner avatar Dec 09 '20 14:12 RobbieTheWagner

I'm realizing the same thing -- I think it's trivial to just use shepherd.js in my Vue app, no real need for this wrapper. I just made a Tour.vue that imports shepherd.js directly.

garyo avatar Dec 09 '20 15:12 garyo

You could also add this to your declaration file to make use of the injected function as intended, with types from shepherd.js

import Shepherd from 'shepherd.js'

declare module 'vue-shepherd'

declare module 'vue/types/vue' {
  // this.$myInjectedFunction inside Vue components
  interface Vue {
    $shepherd: (...args: any[]) => Shepherd.Tour
  }
}

jim-toth avatar Mar 08 '21 21:03 jim-toth

@jim-toth perhaps we should use that as the types for this repo? I would definitely accept a PR adding a types file.

RobbieTheWagner avatar Mar 09 '21 14:03 RobbieTheWagner

if i use declare module 'vue-shepherd' i get error ts2665: invalid module name in augmentation. Module 'vue-shepherd' resolves to an untyped module at '...node_modules/vue-shepherd/dist/vue-shepherd.common.js', which cannot be augmented

manuel-84 avatar May 19 '22 10:05 manuel-84

@manuel-84 sorry to hear that. As mentioned above, I would accept a PR to fix TS. The types exist in Shepherd itself.

RobbieTheWagner avatar May 19 '22 13:05 RobbieTheWagner

For the composition api the following declaration file works really well:

import Shepherd from 'shepherd.js'


declare module 'vue-shepherd' {
  export function useShepherd(...args: Array<Shepherd.Tour.TourOptions>): Shepherd.Tour
}

losfroger avatar Aug 09 '23 21:08 losfroger

If anyone would like to open a PR adding types, I would gladly accept it!

RobbieTheWagner avatar Oct 03 '23 11:10 RobbieTheWagner